[英]Matplotlib - plot lines in more colors than 10
I'm trying to plot 13 different columns from a dataframe in one line graph using matplotlib and I am really struggling to understand how matplotlib works with colors. 在 10 個獨特的 colors 之后,托盤開始循環。
似乎有無數關於如何在 SO 上執行此操作的示例,但是,我對工具的有限理解使得諸如這些安靜的修辭示例無法訪問。 如果我的數據不是任意行集合怎么辦?
更好的是,無論如何我可以永久更改我的 matplotlib 配置以根據需要無限創建新的 colors 嗎?
我已經為此苦苦掙扎了一段時間,並且可以使用您可以提供的任何建議。
如果您正在使用 Pandas dataframe,您可以將cmap
傳遞給plot
:
df.plot(cmap='tab20')
更新:使用 matplotlib:
cmap=plt.get_cmap('tab20')
for i,col in enumerate(df.columns):
plt.plot(df[col], color=cmap(i), label=col)
plt.legend()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.