python - 如何编辑图形的大小?
问题描述
请问如何调整图表的大小?这是我的代码。
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(mean, median, marker="s", linestyle="")
for i, txt in enumerate(words):
ax.annotate(txt, (mean[i],median[i]))
ax.set_xlabel("median")
ax.set_ylabel("mean")
plt.show()
我试着用
fig,ax=plt.subplots(figsize=(20,10))
但失败了。
解决方案
在调整图形大小之前,您首先必须拥有可以执行的代码:
(我添加了虚拟数据,现在它可以工作了)
import matplotlib.pyplot as plt
if __name__ == '__main__':
fig = plt.figure()
ax = fig.add_subplot(111)
mean, median = [1, 2, 3], [4, 5, 6] # dummy data
ax.plot(mean, median, marker="s", linestyle="")
for i, txt in enumerate(['a', 'b', 'c']):
ax.annotate(txt, (mean[i], median[i]))
ax.set_xlabel("median")
ax.set_ylabel("mean")
fig, ax = plt.subplots(figsize=(10, 10)) # size in inches
plt.show()
推荐阅读
- sql - Oracle SQL - 将字段更新为值案例当另一个字段等于某物时
- javascript - 有什么方法可以使用 node.js 运行并将参数传递给 java function\class\jar?
- android - CalendarProvider,如何获取会议的所有者名称?
- android - 我如何解决适配器上的 setOnClickListener
- tensorflow - 结合多个源集做出决策
- c# - 兑换 - LogonHostedExchangeMailbox 错误
- python - 如何使用 python 从 azure function app 中的请求中读取 cookie
- java - 如何使用动画制作包含表情符号的自定义警报对话框
- kubernetes - IBM ICP Auth-pdp 没有响应
- javascript - Tablesorter仅按降序正确排序customely解析的数字,升序是错误的