12

I have intention in making multiple subplot to present my results. I used subplots from matplotlib. I have a problem with text sizes. As you can see in the trivial code here. In the plt.title documentation it says title(label, fontdict=None, loc='center', pad=None, **kwargs)

import random
from matplotlib.pyplot import figure, plot, xlabel, ylabel, legend, close, subplots, title, savefig, get_current_fig_manager, show, pause, clf

x = []
for i in range(10):
    x.append(random.random()*i)

y_1 = []

for i in range(10):
    y_1.append(random.random()*i)
y_2 = []

for i in range(10):
    y_2.append(random.random()*i)


fig, ax = subplots(1, 2, squeeze = False, figsize = (10,10))
ax[0,1].title.set_text('y_1', fontdict = {'font.size':22})
ax[0,1].plot(x,y_1)
ax[0,1].set_xlabel('x')
ax[0,1].set_ylabel('y_1')

ax[0,0].title.set_text('y_2', fontdict = {'font.size':22})
ax[0,0].plot(x,y_2)
ax[0,0].set_xlabel('x')
ax[0,0].set_ylabel('y_2')

but if I run this code I get an error TypeError: set_text() got an unexpected keyword argument 'fontdict'

am I using the wrong command.

2 Answers 2

22

This is really just a minor issue:

To set the title of a specific axes you should use the set_title method of the axes. Using plt.title sets the title of the current axes instance.

Basically replace your ax[0,0].title.set_text with ax[0,0].set_title and you are good to go!

0
3

You can also simply use fontsize=22 directly , as in ax[0,1].set_title('y_1', fontsize=22)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.