python - 缩放 Y 轴和 X 轴 python 图
问题描述
我有一组数据,并使用它们制作了一个图表。问题是数据看起来没有正确缩放,因为 y 轴范围从 0 到 30000,而 x 轴范围从 -2 到 30。我该如何解决这个问题?谢谢
这是我的代码,
import numpy as np
import matplotlib.pyplot as plt
voltage365nm = [-1.877,-2.0,-1.5,-1.0,0.0,5.0,10.0,20.0,30.0]
voltage405nm = [-1.437,-2.0,-1.5,-1.0,0.0,5.0,10.0,20.0,30.0]
voltage546nm = [-0.768,-2.0,-1.5,-1.0,0.0,5.0,10.0,20.0,30.0]
current365nm = [0.0,5.6,151.1,428,1164,5760,9870,1626,20700]
current405nm = [0.0,-8.2,-2.6,70.2,278,1954,2460,3970,5021]
current546nm = [0.0,-6.5,-6.1,-5.4,248,1435,2240,3250,3750] plt.plot(voltage365nm,current405nm,"r--",marker="s",label="$\lambda$=365 nm")
plt.plot(voltage405nm,current405nm,"b-.",marker="o",label="$\lambda$=405nm")
plt.plot(voltage546nm,current546nm,"g-",marker="^",label="$\lambda$=546nm")
plt.legend(loc='best')
plt.xlabel("Voltage (V)")
plt.ylabel("Current (I x $10^{-13}A}$)")
plt.title("Current vs Voltage")
plt.grid(b=True, which='major', color='g', linestyle='--')
plt.grid(b=True, which='minor', color='r', linestyle='--', alpha=0.2)
plt.show()
解决方案
您可以使用plt.xlim([-10,0])
andplt.ylim([-10,0])
来指定轴的最小值和最大值。
推荐阅读
- javascript - Selectize.js:使用默认值填充
- javascript - 如何从 Firebase 快照返回数组
- nginx - nginx centos 7服务器多个网站
- c++ - 如何在 C++ 中使用自动换行符实现日志记录宏
- kotlin - Kotlin 语言是如何用 Kotlin 编写的?
- php - PHP 在 0x03 End of Text 后停止在二进制字符串循环中工作
- amazon-web-services - AWS Lambda@Edge 的缓存选项
- javascript - jQuery UI,响应式调整最后一个 div
- openapi - 在属性中限制 openapi 类型的正确方法是什么?
- ios - 如何在 Swift 中使用滑块值更改 kCIInputBrightnessKey,无论滑块获得什么值,我都会得到白色或黑色图片