首页 > 解决方案 > 缩放 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()                  

标签: pythonmatplotlibgraph

解决方案


您可以使用plt.xlim([-10,0])andplt.ylim([-10,0])来指定轴的最小值和最大值。


推荐阅读