Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (45.3k points)

I am trying to plot two separate quantities on the same graph using twiny as follows:

fig = figure()

ax = fig.add_subplot(111)

ax.plot(T, r, 'b-', T, R, 'r-', T, r_geo, 'g-')


ax.annotate('Approx. sea level', xy=(Planet.T_day*1.3,(Planet.R)/1000), xytext=(Planet.T_day*1.3, Planet.R/1000))

ax.annotate('Geostat. orbit', xy=(Planet.T_day*1.3, r_geo[0]), xytext=(Planet.T_day*1.3, r_geo[0]))

ax.set_xlabel('Rotational period (hrs)')

ax.set_ylabel('Orbital radius (km), logarithmic')

ax.set_title('Orbital charts for ' + Planet.N, horizontalalignment='center', verticalalignment='top')

ax2 = ax.twiny()


ax2.set_xlabel('Linear speed (ms-1)')


and the data is presented fine, but I am having the problem that the figure title is overlapping with the axes labels on the secondary x axis so that it's barely legible (I wanted to post a picture example here, but I don't have a high enough rep yet).

I'd like to know if there's a straightforward way to just shift the title directly up a few tens of pixels, so that the chart looks prettier.

1 Answer

0 votes
by (16.8k points)

Try this:

plt.title(figure_title, y=1.08)

This also works for plt.suptitle(), but not (yet) for plt.xlabel(), etc.

Related questions

Browse Categories