0

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!

toscanelli
  • 1,202
  • 2
  • 17
  • 40

1 Answers1

1

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

Community
  • 1
  • 1
tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • You are completely right. I remove this entire line and it worked perfectly. The only minor problem now is where to indicate the fontsize. – toscanelli Sep 10 '13 at 13:19
  • @toscanelli see edit. If this solved you problem please accept (the big gray check box on the left) the answer. – tacaswell Sep 10 '13 at 13:23