Duel Axes with non-linear labelling


In [1]:
import numpy as np
import matplotlib.pyplot as plt

In [2]:
fig = plt.figure(1,figsize=(8,11))


<matplotlib.figure.Figure at 0x2e3f250>

In [3]:
plt.clf()


<matplotlib.figure.Figure at 0x2e3f110>

In [44]:
ax1=plt.subplot(1,1,1)

ax1.set_xticks(range(10))
ax1.set_xticklabels(['a','b','c','d','e','f','g','h','i','j'],fontsize=16)
ax1.set_yticks([0,10,30,40,70])
ax1.set_yticklabels(['000000','100000','300000','400000','700000'],fontsize=16)

for i in np.arange(0,10,1):
    ax1.plot(np.arange(10),np.repeat(i,10),color='r',marker='.',markersize=10, ls='')
for i in np.arange(10,30,1):
    ax1.plot(np.arange(10),np.repeat(i,10),color='orange',marker='.',markersize=10, ls='')
for i in np.arange(30,40,1):
    ax1.plot(np.arange(10),np.repeat(i,10),color='y',marker='.',markersize=10, ls='')
for i in np.arange(40,70,1):
    ax1.plot(np.arange(10),np.repeat(i,10),color='g',marker='.',markersize=10, ls='')
for i in np.arange(70,100,1):
    ax1.plot(np.arange(10),np.repeat(i,10),color='b',marker='.',markersize=10, ls='')

ax1.set_ylim(0,100)
ax1.set_xlim(0,10)

ax2=ax1.twinx()

# You can do this:
#ax2.set_yticks(range(10))
#ax2.set_yticklabels(range(10),fontsize=16)
# Or this:
ax2.tick_params(axis='both',which='major',labelsize=16)

ax2.plot(range(10),range(10),color='black')
ax2.set_ylim(0,10)

#plt.xticks()
plt.show()



In [ ]: