Reputation: 647
I have a pandas data frame with 5 different column. I want to plot them with different color, lable, and marker for each column. I manage to make a different color and different label for each column, by passing a list of colors/label for each column. However this does not work for the marker. Any idea on how to do it? Here is the code example:
ds # a pandas data frame with 3 columns
list_label=['A','B','C']
list_color=['tab:red','tab:green','tab:blue']
list_marker=['o','s','v']
ds.plot(color=list_color, label=list_label, marker=list_marker)
The later line produce an error like AttributeError: 'Line2D' object has no property 'list_marker'
Upvotes: 1
Views: 663
Reputation: 59519
Plot each Series separately on the same figure so you can specify the correct marker.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.randint(1, 10, (10, 3)))
list_label=['A', 'B', 'C']
list_color=['tab:red', 'tab:green', 'tab:blue']
list_marker=['o', 's', 'v']
fig, ax = plt.subplots()
for i, col in enumerate(df):
df[col].plot(color=list_color[i], marker=list_marker[i], label=list_label[i], ax=ax)
plt.legend()
plt.show()
Upvotes: 3