Note that there are some explanatory texts on larger screens.

plurals
  1. POAxes tick label padding in matplotlib
    text
    copied!<p>I'm trying to make a pseudocolour image plot in Python Matplotlib, but I'm having a small problem with the layout- the axes tick labels are very small numbers (1e-7 or so), so Matplotlib puts an exponent on the entire axis. This is good, but it overlaps with the x axis label and the title!</p> <p><img src="https://i.stack.imgur.com/Zk0XU.png" alt="See how the title overlaps with &quot;1e-7&quot;!"></p> <p>Is there a better way to fix this other than just hacking the title upwards and the xlabel downwards (and if this is the way to go, what's the best way to do this?) I'm trying to plot a lot of different things with maximal code reuse, so if Matplotlib has a way to fix this without channging text positioning manually that would be the best!</p> <p>Here's how I'm generating this plot:</p> <pre><code>fig = Figure(figsize=(5.5, 4.25)) ax = fig.add_subplot(111) ax.set_title('The title', size=12) ax.set_xlabel('The xlabel', size=10) ax.set_ylabel('The Ylabel', size=10) ax.ticklabel_format(scilimits=(-3,3)) pcm = ax.pcolor(X, Y, Z, cmap=cm.jet) #X,Y is a meshgrid and Z is the function evaluated on it ax.get_figure().colorbar(pcm, ax=ax, use_gridspec=True) ax.set_axes([0, 1e-3, -5e-7, 5e-7]) #Some code for the hatching at the top and bottom of the plot for ticklabel in ax.get_xticklabels(): ticklabel.set_size(8) for ticklabel in ax.get_yticklabels(): ticklabel.set_size(8) ax.get_xaxis().get_offset_text().set_size(8) ax.get_yaxis().get_offset_text().set_size(8) fig.subplots_adjust() c = FigureCanvas(fig) c.print_figure('filename.png', dpi=300) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload