0

I am creating a plot in matplotlib using the following commands:

    fig = plt.figure()
    ax = plt.axes() 
    ax.plot ( xdata, ydata )
    my_cmap = cm.seismic
    ax.tick_params ( axis='x', labelsize=16 )
    ax.tick_params ( axis='y', labelsize=16 )
    sm = plt.cm.ScalarMappable ( cmap=my_cmap, norm=plt.Normalize(vmin=0, vmax=1) )
    cbar = plt.colorbar(sm, orientation='vertical') 
    cbar.set_ticks ( [0, 1] )
    cbar.set_ticklabels( ["Poorest", "Best"] ) 
    cbar.ax.tick_params(labelsize=14)
    cbar.ax.set_ylabel ("Quality of solvent", fontsize=18, rotation=270)
    ax.set_xscale('log')
    ax.set_xlabel ( "Temperature (reduced)", fontsize=18) 
    ax.set_ylabel ( "$\\xi$", fontsize=18)
    ax.yaxis.set_major_locator(matplotlib.ticker.MaxNLocator(11))
    ax.set_yticks (np.linspace(0, 1, 11)) 
    fig.tight_layout ()
    plt.savefig   ( "DOP_"+str(dop)+"_parameter.png", dpi=1000)

I am getting the following image: enter image description here

This post: How do I extend the margin at the bottom of a figure in Matplotlib? suggested I use plt.tight_layout(), but that evidently did not work. How do I add additional space to the bottom of the plot, while maintaining the yrange from 0.0 to 1.0?

bad_chemist
  • 283
  • 1
  • 7
  • 2
    `ax.set_ylim(bottom=-0.05)`, IIUC? Or what do you mean by "space at the bottom"? – mcsoini Jul 04 '22 at 08:51
  • I meant that the markers for the ydata should be entirely visible. but your simple solution worked. Thank you! – bad_chemist Jul 04 '22 at 09:08
  • Note that your code isn't reproducible, as is misses test data (and the necessary imports). Also, the code you show doesn't seem to set the y limits nor the markers. You could use the parameter `clip_on=False` while plotting to avoid that the markers are clipped in half by the x-axis. – JohanC Jul 04 '22 at 09:12
  • Also note that `ax = plt.axes()` isn't the recommended way to create subplots. `fig, ax = plt.subplots()` (and leaving out both `fig = plt.figure()`and `ax = plt.axes()`) works a lot better with most matplotlib functions. Tutorial docs: https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.html – JohanC Jul 04 '22 at 09:16
  • You also have a setting somewhere the limit be from 0-1. But default matplotlib auto limits with margins around the data. – Jody Klymak Jul 04 '22 at 09:19

0 Answers0