Issue
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.
Solution
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!
Answered By - jojo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.