gpt4 book ai didi

python - 缩放Y轴和X轴Python图

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:10 33 4
gpt4 key购买 nike

我有一组数据,并使用它们制作了一个图表。问题是数据看起来没有正确缩放,因为 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])plt.ylim([-10,0]) 指定最小值和最大值你的轴。

关于python - 缩放Y轴和X轴Python图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55183685/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com