【发布时间】:2017-11-12 15:35:58
【问题描述】:
我有以下路径数据框,属于同一“uid”的 (x,y) 点被认为是一个单独的路径。
uid x y
0 5 1 1
1 5 2 1
2 5 3 1
3 5 4 1
4 21 4 5
6 21 6 6
7 21 5 7
8 25 1 1
9 25 2 2
10 25 3 3
11 25 4 4
12 25 5 5
13 27 1 3
14 27 2 3
15 27 4 3
以下是我用来绘制这些路径的代码:
%matplotlib notebook
fig, ax = plt.subplots(figsize=(12,8))
df.groupby("uid").plot(kind='line', x = "x", y = "y", ax = ax)
plt.title("Paths")
#ax.legend_.remove()
plt.show()
由于 matplotlib 自动为图中的每条线生成颜色,我想根据路径的 "uid" 控制从我的 df 生成的路径的颜色。
假设我想保持为 uid=25 和 uid=27 only 生成的路径的颜色为 green 其余为黑色。
另外,我想将 uid=25,27 的 "kind" 行更改为 dotted,而所有其他行都应该是简单的行。我怎样才能做到这一点?
【问题讨论】:
标签: python pandas matplotlib dataframe graph