Pregunta

My axis labels often look not good (too close to tick labels) when I use Matplotlib.

test image

How to set distance between tick labels and axis label? I just need to enlarge distance between "Number of stars" label and corresponding tick labels. Maybe latex \vspace{} is working but I don't know how to implement it. fig.subplots_adjust(left=) is not a solution.

¿Fue útil?

Solución

To move the axis label further away from the axis, you can include an argument to the optional labelpad parameter of the corresponding method used to set the label, i.e. ax.set_ylabel() or ax.set_xlabel(). This parameter takes a scalar which is the spacing between the axis and the label given in points.

As to achieve the same effect when using the drawparallels() method of Basemap, I believe you can include an argument to the parameters xoffset or yoffset, depending on which axis you want to alter the placement of the text. The arguments of these parameters have "units" of map width, meaning e.g. xoffset=0.05 makes the offset of the x-ticks 5 % of the map width.

Otros consejos

This is a really subjective question, but I'll take a stab anyway:

The figsize kwarg takes the width and height of the figure in inches.

A4 paper is 8.3" by 11.7". So let's say, for the sake of argument, you want 1" margins.

paperheight = 11.7
paperwidth = 8.3
margin = 1.0

fig = plt.figure(figsize=(paperwidth - 2*margin, paperheight - 2*margin))

# plotting stuff

fig.tight_layout()
fig.savefig(...)

The call to tight_layout() will give the labels a bit more room and make sure that everything is expanded out to the figure edges as much as practicable.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top