python - 如何使用轴和子图设置 matplotlib figsize
问题描述
您好,我有一个非常基本的 matplotlib 绘图,但我希望能够设置图形大小,我对不使用多个子图时如何执行此操作感到困惑。我对 figsize 和 subplots 之间的关系感到困惑,请参见下面的代码:
plt.figure(figsize=(10,10))
y = np.arange(1,6,1)
y1 = y**2
y2 = y**3
y3 = y**4
x = np.arange(1,101,20)
fig, ax = plt.subplots()
ax.plot(x,y1)
ax.plot(x,y2)
ax.plot(x,y3)
解决方案
只需放入 1 行和 1 列子图,就可以得到一个图。
fig, ax = plt.subplots(1, 1, figsize=(8,8))
y = np.arange(1,6,1)
y1 = y**2
y2 = y**3
y3 = y**4
x = np.arange(1,101,20)
fig, ax = plt.subplots()
ax.plot(x,y1)
ax.plot(x,y2)
ax.plot(x,y3)
fig.savefig('eightbyeight.png', dpi = 300)
推荐阅读
- javascript - JQuery ajax GET request calls success with truncated data
- python - Python - 当另一列中的数字大于之前的数字时,将列中的 x 值保存到列表
- html - 如何让文本溢出与嵌套在 flexbox 内的 div 一起使用
- r - 如何在 R Markdown 中添加目录?
- javascript - 使用正则表达式提取子字符串
- ios - 如何在 SwiftUI 中的文本中为子字符串加下划线?
- python - tf.keras.models.clone_model 未知激活:ReLU
- excel - 更新一行中某个单元格的值发生变化的时间
- python - 如果子字符串的数量不相等,为什么我的代码应该为 False 时返回 True?
- c# - 如何使用 Selenium 和 C# 点击登录按钮