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.
pyplot. title() method to assign a title to a plot, so in order to change the font size, we are going to use the font size argument of the pyplot. title() method in the matplotlib module.
We can also add title to subplots in Matplotlib using title. set_text() method, in similar way to set_title() method.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With