python - Python 绘图图
问题描述
from matplotlib.pyplot import *
list = [1,3,5,7,2,4,6,8,10]
plot(list)
使用上面的代码,代码将绘制 x 轴从 0 到 8 的图形。如果我希望我的 x 轴从另一个值运行,我该怎么办?即我的 x 轴从 120-128 运行?
解决方案
您可以只使用该show()
功能来显示图表。您的代码应该看起来像这样。
from matplotlib.pyplot import *
list = [1,3,5,7,2,4,6,8,10]
plot(list)
show()
而且,正如@BcK 的评论中所提到的,不要使用关键字或内置函数名称作为变量名,最后不要import *
,这不是一个好习惯。您可以将整个程序更新为:
import matplotlib.pyplot as plt
var_list = [1,3,5,7,2,4,6,8,10] # don't use keywords or inbuilt function names as varible names
plt.plot(var_list)
plt.show() # this is to visualize the plot
推荐阅读
- java - Keycloak 适配器 pkix 路径构建失败
- firebase-realtime-database - 如何在单个活动中检索不同的子 Firebase 数据库
- c++ - C ++:释放构造函数中所需的障碍,该构造函数创建访问构造对象的线程
- java - 通过多部分请求直接将文件上传到 FileInputStream 的 Jetty 文件
- java - 有 1 个数据节点正在运行,并且在此操作中排除了 1 个节点。(伪分布式模式)
- microsoft-graph-api - Microsoft Graph - 最近的端点不返回最近使用的文件
- android - 如何获取 itemView 追星族回收站视图
- javascript - 在wordpress中导入脚本
- string - 如何将字符串(具有固定分隔符)转换为要附加到 JSON 的数组?
- visual-studio - 创建自定义 TFS 用户并授予/拒绝其权限