1
我正在使用熊貓0.18。我有這樣一個數據幀:添加傳說以散點圖區分顏色?
code proportion percent_highcost total_quantity
A81 0.7 76 1002
A81 0.0 73 1400
而且我畫的散點圖這樣的:
colours = np.where(df['proportion'] > 0, 'r', 'b')
df.plot.scatter(y='percent_highcost', x='total_quantity', c=colours)
這個效果很好,但我不知道如何添加一個傳說,表示什麼兩種顏色的意思。
我試過plt.legend(['Non-dispensing', 'dispensing'], loc=1)
但是這會產生一個奇怪的結果 - 我猜是因爲只有一個系列:
誰能指教?
我建議使用'fig.colorbar(SC)''那裏是sc'藝術家「分散」。您可能不得不使用'ax.scatter'而不是'df.plot'來輕鬆訪問該藝術家。 – tacaswell