python-3.x - Python:如何在函数外使用函数中定义的图形?
问题描述
我有这个代码:
def functionPlot():
ax = plt.figure().add_subplot(111)
ax.plot([1,1])
return ax
if __name__=="__main__":
ax=functionPlot()
我想获得在函数“functionPlot”中定义的图形,以便在“main”函数中使用。我无法做到这一点。我怎样才能做到这一点?我应该从函数返回什么?
解决方案
也许你的意思是:
import matplotlib.pyplot as plt
def functionPlot():
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1,1])
return fig
if __name__=="__main__":
fig = functionPlot()
# do other things with fig
推荐阅读
- python - python中虚拟环境的命名规则
- javascript - firebase/firestore 不工作,但 firebase/firestore/lite 是
- python - 让 Python 3 等待键盘输入
- odoo-14 - 即使在 odoo 14 中使用管理员登录也无法访问电子邮件
- java - 在 ubuntu tomcat 上找不到类 com.sun.ws.rs.ext.RuntimeDelegateImpl
- flutter - 如何在颤动中将三位十六进制字符串转换为颜色
- json - Scala - 如何读取超过 4096 个字符的 MQ 消息
- mysql - 编写一个选择查询以使用另一个表字段值获取表值
- function - 是否有一个内置函数可以获取数据类型条目的名称?
- sql - 删除条目的最旧版本