【问题标题】:How to fix matplotlib y axis numbers not consistant [duplicate]如何修复matplotlib y轴数不一致[重复]
【发布时间】:2019-11-09 15:48:10
【问题描述】:

我试图获得一个易于阅读的图表,但是当我使用 matplotlib.pyplot 绘制它时,y 轴的读数与 x 轴的读数不一致(y 轴从 26 到25 到 24 到 37 等)我做错了什么!

temp = ['26', '26', '25', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24', '24']

hum = ['37', '38', '38', '39', '39', '40', '40', '40', '40', '40', '40', '40', '40', '41', '40', '39', '39', '39', '39', '39', '39', '39', '39']

time = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115]

plt.plot(time, temperature, color="green")
plt.plot(time, humidity, color="orange")
plt.xlabel("time (minutes)")
plt.ylabel("Temp/Humidity (C,%)")
plt.title("Temp and Humidity over time")
plt.show()

我的结果绘制正确,但在恒定方面绘制得很差

【问题讨论】:

    标签: python matplotlib plot axis


    【解决方案1】:

    您的数据被读取为string,您需要自己转换为int(或浮点数)

    temp = list(map(int, temp)) # change data from string to int
    hum = list(map(int, hum))
    plt.plot(time, temp, color="green")
    plt.plot(time, hum, color="orange")
    plt.axis([None, None, 0, 45])  # if you to set Y limits
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      • 1970-01-01
      • 2022-12-21
      • 2015-06-10
      • 2018-06-13
      • 2015-02-14
      相关资源
      最近更新 更多