usernumber
usernumber

Reputation: 2186

Pyplot title vertical position

I would like the title of my plot to be within the plot. With plt.title, I can only adjust left/right/center and I can't set vertical position. I am also using a legend, so using plt.legend as a workaround to setting the position of the title doesn't work. How can I get title to set the title inside the plot rather than above?


"Default" is where plt.title sets the title. "Title" is where I would like the title to be.

Example figure

I want the vertical position of the title to be just under the top of the plot regardless of plot resizing.

Upvotes: 0

Views: 1383

Answers (2)

aemonge
aemonge

Reputation: 2347

From this other post:

ax.yaxis.set_label_position("right")
ax.yaxis.tick_right()

If you're dealing with images, and just want to show the title image horizontally on the right, you need to remove ticks

ax.set_ylabel("image\nlong\ntitle", fontsize=10)
ax.yaxis.set_label_position("right")
ax.tick_params(axis='y')
ax.set_xticks([])
ax.set_yticks([])

Upvotes: 0

anerlich
anerlich

Reputation: 107

Have you tried something like plt.title("Title", y=0.9)?

Upvotes: 1

Related Questions