python - 带有axes.title.set_text的子图中的标题字体
问题描述
我打算制作多个子图来展示我的结果。我使用了 matplotlib 的子图。我有文字大小的问题。正如您在此处的简单代码中看到的那样。在plt.title
文档中它说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')
但是如果我运行此代码,我会收到错误TypeError: set_text() got an unexpected keyword argument 'fontdict'
我是否使用了错误的命令。
解决方案
推荐阅读
- laravel-5.8 - 如何在 laravel5.8 的一个控制器中从不同模型中获取数据?
- sql - 按年份统计记录总数
- asp.net-core - 使用自定义身份验证方案授权失败 - asp.net-core 3.0
- java - 无法使用来自另一个本地依赖模块的接口或类
- javascript - 一次滚动一个 div 的按钮
- python - 来自 pandas read_sql 的“TypeError:'NoneType' 对象不可迭代”
- android - 无法在我的 android 应用程序中创建数据库
- powerbi - 检索与 Power BI 中特定状态相关的最后一条消息
- java - java - 如何在java maven项目中修复“没有GET映射”以显示自定义错误页面?
- css - 更改按钮文本颜色