python - major ticks with locator_params -


i cannot display major ticks of 1st, 2nd, 3rd y-axis @ same level. if have @ figure below 1 can see that:

  • y-left axis has 10 bins (grid on)

  • 1st y-right axis has 7 bins , major ticks not aligned of y-left axis

  • 2nd y-right axis has 9 bins , major ticks not aligned neither ones of y-left axis or 1st y-right axis.

i had found topics here suggest use "locator_parameters":

    plt.locator_params(axis='y', nbins=10)  

but haven't manage make work in case. want have 10 bins y-axis , want major ticks aligned.

enter image description here

    import numpy np     import pandas pd     import matplotlib.pyplot plt     matplotlib import rcparams     %matplotlib inline     x = np.random.rand(20)     y1 = x*5     y2 = x*5 + 0.2     y3 = x*x*3.5 + 0.2*x     y4 = x*5 + 0.2*x     ylimmin = 0     ylimmax = 2.1     linewidth = 1.0     fontsize = 24     subtitle = ""      plt.rcparams.update({'axes.labelsize': 'small'})     fig = plt.figure(figsize=(21,29.7))     ax11 = fig.add_subplot(411)      subplotadjustright = 0.90     mks = 19 # marker step     ax11.plot(x,y1, linestyle='-', linewidth=linewidth, color = 'k',       marker='*', markevery=11*mks,        label="co")     ax11.set_ylabel('co [%]', color='k')     plt.ylim((0,5))     fig.suptitle(subtitle, fontsize = fontsize)     ax11.yaxis.grid()     ax11.locator_params(axis='y', nbins=10)     ax12=ax11.twinx()     ax12.plot(x,y2,linestyle='-', linewidth=linewidth, color='r',       marker='*', markevery=11*mks,        label="co22")     ax12.set_ylabel('no [%]', color='r')     plt.ylim((0,13))     ax12.locator_params(axis='y', nbins=10)      ax13= ax11.twinx()     rspine = ax13.spines['right']     rspine.set_position(('axes', 1.05))     ax13.set_frame_on(true)     ax13.plot(x,y3,linestyle='-', linewidth=linewidth, color='m',       marker='*', markevery=11*mks,        label="co222")     ax13.set_ylabel('o [%] ', color='m')     plt.ylim((0,22))     ax13.locator_params(axis='y', nbins=10) 

ax14.set_yticks(np.linspace(ax14.get_ybound()[0], ax14.get_ybound()[1], 11))

x = np.random.rand(20) y1 = x*5 y2 = x*5 + 0.2 y3 = x*x*3.5 + 0.2*x y4 = x*5 + 0.2*x #from matplotlib.ticker import autominorlocator ylimmin = 0 ylimmax = 2.1 linewidth = 1.0 fontsize = 24 subtitle = ""   plt.rcparams.update({'axes.labelsize': 'small'}) fig = plt.figure(figsize=(21,29.7)) ax11 = fig.add_subplot(411)  subplotadjustright = 0.90 mks = 19 # marker step #matplotlib.locator.maxticks = 5 ax11.plot(x,y1, linestyle='-', linewidth=linewidth, color = 'k',                      marker='*', markevery=11*mks,                       label="co") ax11.set_ylabel('co [%]', color='k') plt.ylim((0,5)) fig.suptitle(subtitle, fontsize = fontsize) ax11.yaxis.grid() #ax11.locator_params(axis='ax11', nbins=10) ax11.set_yticks(np.linspace(ax11.get_ybound()[0], ax11.get_ybound()[1], 11))  ax12=ax11.twinx() ax12.plot(x,y2,linestyle='-', linewidth=linewidth, color='r',                 marker='*', markevery=11*mks,                  label="co22") ax12.set_ylabel('no [%]', color='r') plt.ylim((0,13)) #ax12.locator_params(axis='ax11', nbins=10) ax12.set_yticks(np.linspace(ax12.get_ybound()[0], ax12.get_ybound()[1], 11))  ax13= ax11.twinx() rspine = ax13.spines['right'] rspine.set_position(('axes', 1.05)) ax13.set_frame_on(true) ax13.plot(x,y3,linestyle='-', linewidth=linewidth, color='m',                 marker='*', markevery=11*mks,                  label="co222") ax13.set_ylabel('o [%] ', color='m') plt.ylim((0,22.87)) #ax13.locator_params(axis='ax11', nbins=10) ax13.set_yticks(np.linspace(ax13.get_ybound()[0], ax13.get_ybound()[1], 11))  ax14= ax11.twinx() rspine = ax14.spines['right'] rspine.set_position(('axes', 1.10)) ax14.set_frame_on(true) ax14.plot(x,y4,linestyle='-', linewidth=linewidth, color='m',                 marker='*', markevery=11*mks,                  label="co2") ax14.set_ylabel('co [%] ', color='m') plt.ylim((0,25)) #ax14.locator_params(axis='ax11', nbins=10) ax14.set_yticks(np.linspace(ax14.get_ybound()[0], ax14.get_ybound()[1], 11)) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -