Chris Chris - 1 year ago 79
Python Question

Can't access matplotlib title fontsize when not centered

Not sure what's going on here. If I set

method no longer points to the non-centered title.

How do I access the fontsize of a left aligned title?

import matplotlib.pyplot as plt

# Set up a blank plot
fig, ax = plt.subplots()

# Set title with fontsize of 30
ax.set_title('test_title', loc='left', fontsize=30)

# fontsize of title is 12.0?
print ax.title.get_fontsize()


Answer Source

From docs:

Set one of the three available axes titles. The available titles are positioned above the axes in the center, flush with the left edge, and flush with the right edge.

So, there are 3 different titles. When you execute dir(ax) you can notice there '_left_title' and '_right_title'. So:

fig, ax = plt.subplots()
ax.set_title('test_title', loc='left', fontsize=30)
print ax._left_title.get_fontsize()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download