简体   繁体   中英

How to plot different column of a Pandas data frame with different marker, using pandas.plot() function?

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'

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM