更改图例文本而不更改颜色

时间:2018-10-24 10:28:17

标签: python pandas matplotlib colors legend

我写了一个代码在一个图形上绘制一些数据。当我绘图时,图例似乎还不错,但是一旦我为图例(代码的最后一行)创建了新标签,颜色就与图不对应。我的代码如下:

ax = plt.gca() 
for i in range (len(input_files)):
    df = pd.read_csv(input_files[i], sep= '\t', header=9)
    df = df[df["Z''(b)"] <= 0.0001]
    df.sort_values(by=["Z'(a)"], inplace= True)

    df.plot(ax=ax, x="Z'(a)",y= "Z''(b)",  figsize=(15,5),style='.-' )

    ax.set_ylim(ymin=0.00005)
    plt.ylabel("Z''(b) / Ω")
    plt.xlabel("Z'(a) / Ω")
    plt.axhline(y=0)
    ax.set_ylim(ymax=-0.00025)  
    ax.set_xlim(xmin=0.0006)    
    ax.set_xlim(xmax=0.0016)


    plt.grid() 
    plt.title('Cell 001 - Impedance analysis at 50% SOC')
ax.legend(["Beginning",'300 cycles','600 cycles', '900 cycles','1200 ....])

最初的抓图看起来像这样: I want these colours with different text

但是最终却是这样的: enter image description here

0 个答案:

没有答案