1

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'

1 Answer 1

3

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()

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the idea! But I was wondering if there was a solution without using a loop, as it can be done for the color or the label keyword.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.