首页 > 解决方案 > different linestyle/marker for each line in my 20 lines line plot

问题描述

I`m trying to have a different linestyle or marker for each line in my plot to have the plot more visually appealing to me, I tried to give different colors using (hsv) but the colors are still close to each other which prevent me to differentiate between the lines, here is my code:

plt.figure(figsize=(15,15))
import matplotlib.colors as colors
i=1
for cluster_index in [0,1,2]:

    plt.subplot(3,1,cluster_index + 1)


    for index, row in data_consumption2.iterrows():

        if row.iloc[-1] == cluster_index:
            hsv = ((1/25)*i, 0.2+ (i%2)/2,.8)
            plt.plot(row.iloc[1:-1] , color =colors.hsv_to_rgb(hsv) ,marker='v', alpha=1)
            i+=1

        plt.legend(loc="best")


    plt.plot(kmeans.cluster_centers_[cluster_index], color='k' ,marker='o', alpha=1)

    plt.xticks(rotation='vertical')
    plt.ylabel('Electricity Consumption')
    plt.title(f'Cluster {cluster_index}', fontsize=20)

plt.tight_layout()
plt.show()

I`ve 25 different lines in the second cluster and I hope if anyone can give me tips to change the linestyle in each iteration of the for loop

标签: pythonmatplotlibcluster-analysis

解决方案


推荐阅读