[Matplotlib-users] subplots and xticklabels

Kees Serier kees.serier at gmail.com
Wed Apr 29 09:53:23 EDT 2020


Hi,

I have been making some graphs with multiple curves with Python 3.7.5 and
Matplotlib 3.0.2.
Now I want to plot 4 curves in 3 graphs with subplot.
This works and the 3 graphs are plotted correctly, including the legends.
Only I can't get my X values printed, like I did in my previous graphs with:

labels = ax.get_xticklabels()
plt.setp(labels, fontsize=6, rotation = 90.)

My script is like:

ax = plt.axes()
name_list = tuple(X)
pos_list = np.arange(len(name_list))
ax.xaxis.set_major_locator(ticker.FixedLocator((pos_list)))
ax.xaxis.set_major_formatter(ticker.FixedFormatter((name_list)))
grid_size = (3,1)
fig = plt.figure()

plt.subplot2grid(grid_size, (0, 0), rowspan = 1, colspan = 1)
plt.plot(pos_list, value_list[0], label = "r/s")
plt.plot(pos_list, value_list[1], label = "w/s")
plt.title(plt_title)
plt.legend(loc = 'lower left', fontsize=6)
plt.grid(True)
#plt.setp(labels, visible=False) # does not work

plt.subplot2grid(grid_size, (1, 0), rowspan = 1, colspan = 1)
plt.plot(pos_list, value_list[2], label = "blks/s (kB)")
plt.legend(loc = 'lower left', fontsize=6)
plt.grid(True)
#plt.setp(labels, visible=False) # does not work

plt.subplot2grid(grid_size, (2, 0), rowspan = 1, colspan = 1)
plt.plot(pos_list, value_list[3], label = "avser (ms)")
plt.legend(loc = 'lower left', fontsize=6)

labels = ax.get_xticklabels()
plt.setp(labels, fontsize=6, rotation = 90.)
fig.subplots_adjust(hspace=0)

plt.grid(True)
plt.show()

I have tried a lot of things, but can't get it working.

Thank you in advance,

Kees
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20200429/56cef35c/attachment.html>


More information about the Matplotlib-users mailing list