[Matplotlib-users] subplots and xticklabels

Thomas Caswell tcaswell at gmail.com
Fri Jun 26 19:50:20 EDT 2020


Sorry for the late reply.

It is a bit hard to be sure because your code has a lot on undefined
variables, but I suspect that you are positioning the Axes so that the
ticklabels are place outside of the figure space (and hence are not
rendered).

I suggest trying

fig.tight_layout() before showing or passing `tight_layout=True` when
creating your figure.

Tom

On Wed, Apr 29, 2020 at 9:53 AM Kees Serier <kees.serier at gmail.com> wrote:

> 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
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>


-- 
Thomas Caswell
tcaswell at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20200626/c612497d/attachment.html>


More information about the Matplotlib-users mailing list