有沒有辦法設定引數以在散點圖中對色調值進行排序?例如,我只想顯示 3 個值并具有 3 種不同的顏色。在下面的圖表中,seaborn 自動生成 6 個值并分配了一種顏色。我正在嘗試做這樣的事情:如果 X > 0.06 red,介于 0.06 和 0.08 yellow 之間,以及高于 red 的所有內容。我閱讀了檔案,但仍然無法弄清楚如何實作這一目標
我的代碼:
plt.figure(figsize=(12,8))
sns.scatterplot(x='lng_dms_to_lng_dd',y='lat_dms_to_lat_dd',data=store_avg,hue='MOP_GC_PCT', size="MOP_GC_PCT",sizes=(20, 200))

uj5u.com熱心網友回復:
您可以嘗試為您的條件創建一個帶有新標簽的新列,并使用色調作為新列繪制圖形。
# create new column and label with defined conditions
store_avg.loc[(store_avg['MOP_GC_PCT'] >= 0.09), 'MOP_GC_PCT_bins'] = 'more than 0.08'
store_avg.loc[(store_avg['MOP_GC_PCT'] >= 0.06) & (store_avg['col1'] <= 0.08), 'MOP_GC_PCT_bins'] = 'between 0.06 and 0.08'
store_avg.loc[(store_avg['MOP_GC_PCT'] <= 0.05), 'MOP_GC_PCT_bins'] = 'less than 0.06'
# your plot code
plt.figure(figsize=(12,8))
sns.scatterplot(x='lng_dms_to_lng_dd',y='lat_dms_to_lat_dd',data=store_avg,hue='MOP_GC_PCT_bins', size="MOP_GC_PCT",sizes=(20, 200))
您還可以定義自己的調色板。
# define palette
palette = {'more than 0.08':'red',
'between 0.06 and 0.08':'yellow',
'less than 0.06':'red'}
# plot with custom palette
sns.scatterplot(x='lng_dms_to_lng_dd',y='lat_dms_to_lat_dd',data=store_avg,hue='MOP_GC_PCT_bins', size="MOP_GC_PCT",sizes=(20, 200), palette=palette)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/462363.html
標籤:熊猫 matplotlib 海运
下一篇:分組X軸離散變數Pyplot
