[英]How do I create a Box plot for each column in a Pandas Dataframe?
[英]How can I plot a pandas dataframe with different line colors for each column?
問題標題說明了一切。 我想 plot 一個 dataframe。 比如說,7 行 3 列。 我想用隨機 colors 每列 plot。 我怎樣才能做到這一點?
由於您沒有龐大的數據集,您可以創建一個名為 color_dict 的字典,並在繪圖時從中查找 colors。
import pandas as pd
data = {
'time0': [41, 28, 33, 34, 38, 31, 37],
'time1': [48, 26, 39, 33, 58, 41, 43],
'time2': [53, 30, 51, 37, 48, 49, 53]
}
df = pd.DataFrame(data=data)
import random
color_dict = {}
for idx in range(df.shape[1]):
r = random.random()
b = random.random()
g = random.random()
color = (r, g, b)
color_dict[idx] = color
colors = [color_dict.get(x) for x in range(df.shape[1])]
import matplotlib.pyplot as plt
for idx in range(df.shape[1]):
plt.plot(df.iloc[:,idx], color=colors[idx])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.