我是靠谱客的博主 畅快小兔子,这篇文章主要介绍xaxis python_Python使用数据/时间作为xaxis?,现在分享给大家,希望可以做个参考。

使用unix时间进行绘图非常有效

但我想用实时作为轴(或子轴),但我似乎无法读入或绘制它。在import numpy as np

from mpl_toolkits.axes_grid1 import host_subplot

import mpl_toolkits.axisartist as AA

import matplotlib.pyplot as plt

#import data

data = np.loadtxt('DHT11.csv', delimiter = ',', skiprows = 1,

usecols = (0,2,3,4,5,6), unpack = 1)

#id, unixtime, temp, humidity, lightlevel, lightvolt

i = data[0]

time = data[1]

temp = data[2]

hum = data[3]

light_lv = 1/data[4]*1000

light_v = data[5]

if 1:

host = host_subplot(111, axes_class=AA.Axes)

plt.subplots_adjust(right=0.75)

par1 = host.twinx()

par2 = host.twinx()

offset = 60

new_fixed_axis = par2.get_grid_helper().new_fixed_axis

par2.axis["right"] = new_fixed_axis(loc="right",

axes=par2,

offset=(offset, 0))

par2.axis["right"].toggle(all=True)

#host.set_xlim(0, 2)

#host.set_ylim(0, 2)

host.set_xlabel("Time (unix)")

host.set_ylabel("Temperature (C)")

par1.set_ylabel("Humidity (%)")

par2.set_ylabel("Light (A.U.)")

p1, = host.plot(time, temp)

p2, = par1.plot(time, hum)

p3, = par2.plot(time, light_lv)

#par1.set_ylim(0, 4)

#par2.set_ylim(1, 65)

host.legend()

host.axis["left"].label.set_color(p1.get_color())

par1.axis["right"].label.set_color(p2.get_color())

par2.axis["right"].label.set_color(p3.get_color())

plt.draw()

plt.show()

#plt.savefig("Test")

谁能帮忙吗?在

最后

以上就是畅快小兔子最近收集整理的关于xaxis python_Python使用数据/时间作为xaxis?的全部内容,更多相关xaxis内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(147)

评论列表共有 0 条评论

立即
投稿
返回
顶部