我有来自不同板上多个器件的温度数据,例如,在板1上,我有PCB本身和3个不同FET的温度,同样地,板2和3也有温度。我将数据读入一个dataframe,并希望用相同的颜色为每个测试板绘制数据,但用不同的标记为板上的每个设备绘制数据。例如,板1的所有测量值都是蓝色的,PCB温度使用标记'+',FET1使用标记'V'等。
我像这样读取文件:
for file_name in glob.glob(path+'*.csv'):
filename[i] = os.path.basename(file_name)
print(filename[i])
#x[i]= np.genfromtxt(path+ filename[i], delimiter=',',skip_header=20,usecols=(2,4,6,8))
x[i]=pd.read_csv(path+filename[i], header=0,usecols=[2,4,6,8], skiprows=12,names=['PCB', 'FET1', 'FET2', 'FET3'])
并创建一个数组。
然后我绘制不同的列:
colors=['r','b','g','c','m']
for i in range(len(filename)):
#plt.figure()
plt.plot(sc.decimate(x[i]['PCB'],5),'-+'+colors[i],label="PCB")
plt.plot(sc.decimate(x[i]['FET1'],5),'-v'+colors[i],label='FET1')
plt.plot(sc.decimate(x[i]['FET2'],5),'-x'+colors[i],label='FET2')
plt.plot(sc.decimate(x[i]['FET3'],5),'-o'+colors[i],label='FET3')
leg=np.append(leg, filename[i][0:7])
#plt.show()
plt.show()
plt.legend(leg)
Name:,Data Instr INSTR 3/5/2020 11:51:59,,,,,,,,,,,,
Owner:,lab1,,,,,,,,,,,,
Comments:,,,,,,,,,,,,,
Acquisition Date:,3/5/2020 11:51,,,,,,,,,,,,
&Instrument:,34970A,Address:,ASRL11::INSTR,Modules:,1,Slot3:,34901A,,,,,,
Total Channels:,4,,,,,,,,,,,,
Channel,Name,Function,Range,Resolution,AdvSettings,Scale,Gain,Offset,Label,Test,Low,High,HWAlarm
316,PCB_CTR,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
317,Q24,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
318,Q25,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
319,Q18,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
Scan Control:,Start Action:,Immediately,Stop Action:,User Terminated,,,,,,,,,
Scan,Time,316 <PCB_CTR> (C),Alarm 316,317 <Q24> (C),Alarm 317,318 <Q25> (C),Alarm 318,319 <Q18> (C),Alarm 319,,,,
1,3/5/2020 11:51:59:168,30.471,0,29.241,0,29.165,0,33.302,0,,,,
2,3/5/2020 11:52:01:152,32.197,0,30.634,0,30.564,0,34.819,0,,,,
3,3/5/2020 11:52:03:152,33.795,0,32.019,0,31.879,0,36.848,0,,,,
4,3/5/2020 11:52:05:152,35.315,0,33.383,0,33.236,0,38.282,0,,,,
5,3/5/2020 11:52:07:152,36.965,0,34.734,0,34.62,0,39.946,0,,,,
6,3/5/2020 11:52:09:152,38.255,0,36.054,0,35.776,0,41.18,0,,,,
7,3/5/2020 11:52:11:152,39.467,0,37.328,0,37.028,0,42.258,0,,,,
Name:,Data Instr INSTR 3/5/2020 10:03:21,,,,,,,,,,,,
Owner:,lab1,,,,,,,,,,,,
Comments:,,,,,,,,,,,,,
Acquisition Date:,3/5/2020 10:03,,,,,,,,,,,,
&Instrument:,34970A,Address:,ASRL11::INSTR,Modules:,1,Slot3:,34901A,,,,,,
Total Channels:,4,,,,,,,,,,,,
Channel,Name,Function,Range,Resolution,AdvSettings,Scale,Gain,Offset,Label,Test,Low,High,HWAlarm
316,PCB_CTR,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
317,Q24,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
318,Q25,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
319,Q18,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
Scan Control:,Start Action:,Immediately,Stop Action:,User Terminated,,,,,,,,,
Scan,Time,316 <PCB_CTR> (C),Alarm 316,317 <Q24> (C),Alarm 317,318 <Q25> (C),Alarm 318,319 <Q18> (C),Alarm 319,,,,
1,3/5/2020 10:03:21:164,46.334,0,43.755,0,45.706,0,49.129,0,,,,
2,3/5/2020 10:03:22:149,46.997,0,44.262,0,46.35,0,49.773,0,,,,
3,3/5/2020 10:03:23:149,47.615,0,44.671,0,46.974,0,50.402,0,,,,
4,3/5/2020 10:03:24:149,48.267,0,45.229,0,47.628,0,50.879,0,,,,
5,3/5/2020 10:03:25:149,48.861,0,45.711,0,48.164,0,51.495,0,,,,
6,3/5/2020 10:03:26:149,49.455,0,46.323,0,48.783,0,51.9,0,,,,
7,3/5/2020 10:03:27:149,50.014,0,46.796,0,49.351,0,52.334,0,,,,
Name:,Data Instr INSTR 3/5/2020 13:41:06,,,,,,,,,,,,
Owner:,lab1,,,,,,,,,,,,
Comments:,,,,,,,,,,,,,
Acquisition Date:,3/5/2020 13:41,,,,,,,,,,,,
&Instrument:,34970A,Address:,ASRL11::INSTR,Modules:,1,Slot3:,34901A,,,,,,
Total Channels:,4,,,,,,,,,,,,
Channel,Name,Function,Range,Resolution,AdvSettings,Scale,Gain,Offset,Label,Test,Low,High,HWAlarm
316,PCB_CTR,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
317,Q24,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
318,Q25,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
319,Q18,Temp (Type K),None,C,Temp (Type K)#1#0.016#Auto#0.001#C#Internal#0#false,FALSE,1,0,C,High Only,0,105,Alarm 1
Scan Control:,Start Action:,Immediately,Stop Action:,User Terminated,,,,,,,,,
Scan,Time,316 <PCB_CTR> (C),Alarm 316,317 <Q24> (C),Alarm 317,318 <Q25> (C),Alarm 318,319 <Q18> (C),Alarm 319,,,,
1,3/5/2020 13:41:06:162,28.121,0,26.882,0,28.785,0,31.061,0,,,,
2,3/5/2020 13:41:08:147,30.582,0,27.873,0,30.691,0,33.024,0,,,,
3,3/5/2020 13:41:10:147,31.782,0,28.935,0,32.578,0,34.876,0,,,,
4,3/5/2020 13:41:12:147,34.003,0,30.094,0,34.247,0,36.652,0,,,,
5,3/5/2020 13:41:14:147,35.097,0,31.199,0,35.975,0,38.142,0,,,,
6,3/5/2020 13:41:16:147,36.708,0,32.334,0,37.504,0,39.721,0,,,,
7,3/5/2020 13:41:18:147,38.274,0,33.508,0,39.048,0,41.198,0,,,,
编辑
在@ilke444输入的帮助下,我更接近我想要的东西,但我仍然有一些问题:
for i in range(len(filename)):
l=plt.plot(sc.decimate(x[i]['PCB'],5),'-+'+colors[i],label="PCB")
lines=np.append(lines,l[0].get_label())
l=plt.plot(sc.decimate(x[i]['FET1'],5),'-v'+colors[i],label='FET1')
lines=np.append(lines,l[0].get_label())
l=plt.plot(sc.decimate(x[i]['FET2'],5),'-x'+colors[i],label='FET2')
lines=np.append(lines,l[0].get_label())
l=plt.plot(sc.decimate(x[i]['FET3'],5),'-o'+colors[i],label='FET3')
lines=np.append(lines,l[0].get_label())
linesclr=np.append(linesclr, l) # save color info
names = np.append(names, filename[i][0:7])
fig.legend(lines, loc=1)
fig.legend(linesclr, labels=names, loc=2)
plt.show()
如下所示,我试图添加的第二个图例没有显示正确的颜色,即每个文件读取1个颜色(左上角):
linesclr[0].get_color()
Out[4]: 'r'
linesclr[0].get_color()
Out[5]: 'r'
linesclr[1].get_color()
Out[6]: 'b'
linesclr[2].get_color()
Out[7]: 'g'
+ PCB
v FET1
x FET2
o FET3
左边的图例显示:红色的ACI50#5,蓝色的ACI50#,绿色的ACI50#6,青色的KDE5515(或者无论我读入多少文件,每个文件都有相应的情节颜色)。
我试着在matplotlib上阅读和文学关于传说和创作自定义传说,并在互联网上寻找例子,但我没有太多成功理解我在读什么!
我希望这是你正在寻找的:)
我认为有两种可能的解决方案:
对不起,我不得不提前sim卡数据,所以情节看起来不像有序的线条,但我认为这是没有问题的反正
import glob
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import scipy.signal as sc
import numpy as np
dfs = [] # store df
cmap = cm.get_cmap('Set1')
cols = {}
for i, fn in enumerate(glob.glob("*.csv")) :
#dfs.append(pd.read_csv(fn, header=0, usecols=[2,4,6,8], skiprows=12, names=['PCB', 'FET1', 'FET2', 'FET3'])) # Uncommenting this line to read from your files should work
dfs.append(pd.DataFrame(np.random.randn(100, 4), columns=['PCB', 'FET1', 'FET2', 'FET3'])) # Just random data
cols[i] = cmap(i) # Maps one color to one file with a dict
mrks = {"PCB":'+',"FET1":'v',"FET2":'x',"FET3":'o'} # Maps one sensor to one marker type
fig, ax = plt.subplots(figsize=(12,12))
for n, d in enumerate(dfs) :
ax.plot(sc.decimate(d['PCB'],5), ls='-', marker=mrks['PCB'], color=cols[n], label="PCB") # Use label to map to files
ax.plot(sc.decimate(d['FET1'],5), ls='-', marker=mrks['FET1'], color=cols[n], label="FET1")
ax.plot(sc.decimate(d['FET2'],5), ls='-', marker=mrks['FET2'], color=cols[n], label="FET2")
ax.plot(sc.decimate(d['FET3'],5), ls='-', marker=mrks['FET3'], color=cols[n], label="FET3")
ax.legend()
plt.show()
import glob
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import scipy.signal as sc
import numpy as np
from matplotlib.lines import Line2D
# create a marker for each thermocouple
mrks = {"PCB":'+',"FET1":'v',"FET2":'x',"FET3":'o'}
marker_legend = [Line2D([0], [0], lw=1, color="k", marker=v, label=k) for k, v in mrks.items()]
color_legend = []
dfs = [] # store df
cmap = cm.get_cmap('Set1')
cols = {}
for i, fn in enumerate(glob.glob("*.csv")) : # read files and map colors to each
#dfs.append(pd.read_csv(fn, header=0, usecols=[2,4,6,8], skiprows=12, names=['PCB', 'FET1', 'FET2', 'FET3']))
dfs.append(pd.DataFrame(np.random.randn(100, 4), columns=['PCB', 'FET1', 'FET2', 'FET3']))
cols[i] = cmap(i)
color_legend.append(Line2D([0], [0], color=cmap(i), lw=1, label=fn))
fig, ax = plt.subplots(figsize=(12,12))
for n, d in enumerate(dfs) :
ax.plot(sc.decimate(d['PCB'],5), ls='-', marker=mrks['PCB'], color=cols[n])
ax.plot(sc.decimate(d['FET1'],5), ls='-', marker=mrks['FET1'], color=cols[n])
ax.plot(sc.decimate(d['FET2'],5), ls='-', marker=mrks['FET2'], color=cols[n])
ax.plot(sc.decimate(d['FET3'],5), ls='-', marker=mrks['FET3'], color=cols[n])
first_legend = plt.legend(handles=marker_legend, loc="upper left")
ax = plt.gca().add_artist(first_legend)
second_legend = plt.legend(handles=color_legend, loc="upper right")
plt.show()
cmap = ["r","g","b","cyan", ...]
...
for i, fn in enumerate(glob.glob("*.csv")) :
...
cols[i] = cmap[i]
...
问题内容: 这是我的pandas数据帧’df’: I want to plot 3 groups of bar chart (according to ): for each channel: plot control booked value vs treatment booked value. hence i should get 6 bar charts, in 3 groups where
我对R相当陌生,我有以下疑问: 我试图在R中生成一个有多条线(数据系列)的图。每一行都是一个类别,我希望它有一个独特的颜色。 目前我的代码是这样设置的: 首先,我创建了一个空的情节: 然后,对于我的每个类别,我在这个空图中使用“for”循环绘制线条,就像这样: 这里有8个类别,所以在情节中产生了8条线。正如你所看到的,我试图从彩虹()函数中采样一种颜色来为每一行生成一种颜色。 然而,当绘图生成时,
我有多个数据帧,我想在分组条形图视图中的同一个图上绘制它们。 这是两个非常小的数据帧,我想在同一个图中一起绘制。 数据帧是: 我想画一个像这样的图: 我尝试这样做,只绘制一个图形: 我也试过: 结果只是图片中单个数据帧的数据,而不是两个数据帧的两个数据。请注意,只有两个数据帧的标题出现在同一张图片中,数据仅来自单个独立的数据帧。
我想创建一个包含三条线(男性、女性、未知)的折线图。这是我的数据示例: 是否有一个选项,在图中自动创建三行或我需要循环通过数据和创建三个跟踪自己?到目前为止,这是我的代码:
问题内容: 我开始使用Python(和OOP)进行编程,但是我对Fortran(90/95)和Matlab编程有丰富的经验。 我正在开发一个在tkinter环境上使用动画的小工具。该工具的目标是为多线动画(数组而不是数据向量)。下面是我的问题的一个简单示例。我不明白为什么这两种数据绘制方法的结果如此不同? 如果仅绘制“ dline”,则每条线将分别绘制并使用不同的颜色。如果仅绘制“ mline”,
我目前正在Gmap3上开发一个小应用程序 我的数据集来自一个JS文件,我将其解析为一个data[]数组,在该数组中可以找到每个标记lat、lng、title、(信息窗口)内容和要使用的图标 除了图标颜色之外,所有这些都是一种享受 这个作品: var thiscolor='green';//强制所有图标变为绿色不是我想要的,但它可以工作 ..... 图标:new google.maps.Marker