Reputation: 1241
I have this Python code to plotting a figure:
matplotlib.rcParams['axes.unicode_minus'] = False
fig = plt.figure()
ax = fig.add_subplot(111)
I draw each plot running a loop along x and y like this:
ax.plot(x, y, dotFormat)
ax.errorbar(x, y, yerr=errorStd, fmt=dotFormat)
Finally, I set the axes and show the chart with the interactive navigation:
ax.grid(True)
ax.set_title(chartTitle)
fontsize=10
ax.set_ylabel(yLabel, fontsize=fontsize+2)
ax.set_xlabel(xLabel+'\n', fontsize=fontsize+2)
ax.set_yticklabels(ax.get_yticks(), fontsize=fontsize)
ax.set_xticks(range(len(xMinorLabels)), minor=True)
ax.set_xticklabels(xMinorLabels, minor=True, rotation=90, fontsize=fontsize-5)
ax.set_xticks(xMajorPosition, minor=False)
ax.set_xticklabels(xMajorLabels, minor=False, rotation=90, fontsize=fontsize-4)
plt.show()
If I use the tool zoom-to-rectangle and the Y-axis doesn't work property, because the same dot before zooming in is under 5, and after zooming in it is over 5.
What is happening with the y-axis when I use the zoom tool? Is a bug in the interactive navigation of matplotlib library? Without this tool, the library is useless for huge charts.
Thanks in advance!
Upvotes: 0
Views: 1698
Reputation: 87376
The problem is this
ax.set_yticklabels(ax.get_yticks(), fontsize=fontsize)
section. set_yticklabels
sets the value of the tick independent of the data. That is the third tick will always be the third entry of what ever you passed in.
set_*ticklabels
should be considered dangerous and only used in very specialized situations.
You can set the font size via ax.tick_params(...)
doc, example
Upvotes: 1