[英]How to subplot one column (name) on y-axis and in the same y-axis another column with values
我想在一行中绘制三个 plot:
(标签:绿色 - Plot1:Y1xDay,Plot2:Y2xDay,Plot3:Y3xDay);
(标签:黄色 - Plot1:Y1xDay,Plot2:Y2xDay,Plot3:Y3xDay)。
该行应与 label 列相关,并且每个图形的 x 轴和 y 轴从其他四列接收值。
Label Y1 Y2 Y3 Day
Green 2 6 5 1
Green 8 9 4 2
Green 1 3 9 3
Green 2 1 9 4
Green 7 7 1 5
Green 5 4 8 6
Yellow 1 6 4 1
Yellow 2 8 5 2
Yellow 4 6 5 3
Yellow 2 2 9 4
Yellow 4 3 1 5
Yellow 10 1 4 6
我试图创建一个与不同标签相关的 for 。
plt.figure(figsize=(25,15))
label = np.unique(df['label'])
n_label = len(label)
n = 1
feats = ['k1', 'k2', 'k3']
n_feats = len(feats)
for i in range(len(label)):
for j in range(n_label):
plt.subplot(n_label, n_feats, n)
g = plt.plot (?)
我被困在这里了。 谢谢你。 干杯
我提出了一个子图作为如何使用循环过程绘制图形的示例。
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 3, figsize=(9, 3))
labels = list(df['Label'].unique())
for i,l in enumerate(labels):
x = df[df['Label'] == l]['Day']
y1 = df[df['Label'] == l]['Y1']
y2 = df[df['Label'] == l]['Y2']
y3 = df[df['Label'] == l]['Y3']
axs[i][0].bar(x, y1)
axs[i][1].bar(x, y2)
axs[i][2].bar(x, y3)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.