[英]matplotlib.pyplot.legend Generates different Legends if ran on a different machine
我編寫了一個腳本來自動執行 plot 行,當我運行該腳本時,它在我的機器上運行良好。 但是當其他人嘗試運行相同的腳本時,圖例使用不同的 colors。
這是腳本:
plt.figure(figsize=(15, 9))
plt.style.use('fivethirtyeight')
chart = sns.lineplot(x = pd.to_datetime(buyer_comp_trend['week']).dt.strftime('%m/%d'), y = buyer_comp_trend['Composite Score'], color = '#0000ff', linewidth=7.)
chart = sns.lineplot(x = pd.to_datetime(buyer_comp_trend_ce['week']).dt.strftime('%m/%d'), y = buyer_comp_trend_ce['Composite Score'], color = '#99ccff', linewidth=3.)
chart = sns.lineplot(x = pd.to_datetime(buyer_comp_trend_ea['week']).dt.strftime('%m/%d'), y = buyer_comp_trend_ea['Composite Score'], color = '#990099', linewidth=3.)
chart = sns.lineplot(x = pd.to_datetime(buyer_comp_trend_ma['week']).dt.strftime('%m/%d'), y = buyer_comp_trend_ma['Composite Score'], color = '#1f1f1f', linewidth=3.)
chart = sns.lineplot(x = pd.to_datetime(buyer_comp_trend_ms['week']).dt.strftime('%m/%d'), y = buyer_comp_trend_ms['Composite Score'], color = '#00b050', linewidth=3.)
chart = sns.lineplot(x = pd.to_datetime(buyer_comp_trend_sc['week']).dt.strftime('%m/%d'), y = buyer_comp_trend_sc['Composite Score'], color = '#ff66cc', linewidth=3.)
chart = sns.lineplot(x = pd.to_datetime(buyer_comp_trend_so['week']).dt.strftime('%m/%d'), y = buyer_comp_trend_so['Composite Score'], color = '#996633', linewidth=3.)
chart = sns.lineplot(x = pd.to_datetime(buyer_comp_trend_we['week']).dt.strftime('%m/%d'), y = buyer_comp_trend_we['Composite Score'], color = '#ff8205', linewidth=3.)
plt.plot(pd.to_datetime(buyer_comp_trend['week']).dt.strftime('%m/%d'), buyer_comp_trend['Target'], c = '#808080', ls = '--')
chart.set(title = 'HRX Composite Score (Region scores by week)', ylabel='', xlabel="", facecolor = '#ffffff')
x = range(0, len(pd.to_datetime(buyer_comp_trend['week']).dt.strftime('%m/%d')))
plt.ylim(920, 980)
plt.legend(labels = ['National', 'CE', 'EA', 'MA', 'MS', 'SC', 'SO', 'WE', 'Target (939)'], ncol=9)
我們已經嘗試將 python 更新為相同版本並將 matplotlib 更新為相同版本,但相同的腳本仍然會在不同的計算機上生成不同的圖像。
我終於弄明白了。 問題出在 seaborn 庫上。 出於某種原因,最新版本的 seaborn (0.12.1) 以某種方式弄亂了分配給圖例中每個組的 colors。 將seaborn降級到0.11.2版本后,問題解決。
用於降級 seaborn 的命令是:
pip install --force-reinstall -v "seaborn==0.11.2"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.