在matplotlib中缩放y轴

时间:2020-06-05 06:48:50

标签: python matplotlib

我想在同一个绘图中绘制多个绘图,所以我选择了二维列表,其中一个参数以字符串格式存储值,并且我使用for循环进行相同操作,但是当我在其中绘制较大的值时y轴低于较小的值 这是可能有助于理解的代码段

m=['H','.','<','^','*','+','x','@']
    cnt=0
    for i in all:# here all has the row wise data to plot 
       matplotlib.pyplot.plot(l3,i,m[cnt])# l3 contains the values about the x axis
        cnt=cnt+1
    plt.xlabel("x")
    plt.ylabel("y")
    plt.legend(para,loc='best')# para contains the info about the y parameters

    plt.show()

这样的图形来如何在图形中的0之上获得12000

这是我如何调整比例的图,以便所有值在y轴上按升序排列

This is the plot I got how to rescale it so that all values comes in acsending order on y axis

1 个答案:

答案 0 :(得分:1)

在绘制之前必须将字符串转换为浮点数

for i in all:# here all has the row wise data to plot 
    y = [float(ii) for ii in i]    
    matplotlib.pyplot.plot(l3, y, m[cnt])# l3 contains the values about the x axis
    cnt=cnt+1