推 WayneHong: 感覺直接改原始資料比較快 06/26 08:28
推 yuasa: 先用product_rev.div(1000),把妳的原始資料都除1000。再改 06/26 12:29
→ yuasa: 你ylabel的單位就好了 06/26 12:31
→ treefrog: 不好意思,請問怎麼修改單位? 06/26 12:37
→ gmccntzx1: google “matplotlib FuncFormatter” 06/26 12:42
感謝各位大大解答,後來有找到方式解決,分享給有一樣問題的捧友 :)
# 修改之程式碼:
import pandas as pd
from pandas import read_excel
import matplotlib.pyplot as plt
product_rev=read_excel("revenue.xlsx")
product_rev["2016"]=product_rev["2016"].div(1000) #數字除以1,000
product_rev["2017"]=product_rev["2017"].div(1000) #數字除以1,000
product_rev.sort_values(by="2017",inplace=True,ascending=False)
print(product_rev)
ax =
product_rev.plot.bar(x="Product",y=["2016","2017"],color=["blue","orange"])
plt.title("Total revenue by products",fontsize=16,fontweight="bold")
plt.xlabel("Product")
plt.ylabel("Figure")
# 加上單位 $K
ax.ticklabel_format(axis='y', style='plain')
plt.text(-0.03,1.07,'($K)',
horizontalalignment='center',verticalalignment='center',
transform=ax.transAxes)
# 將 X軸名稱旋轉 45度
ax1=plt.gca()
ax1.set_xticklabels(product_rev["Product"],rotation="45",ha="right")
plt.tight_layout()
plt.show()
#產生 Bar chart如下:(以千為單位計算,標記單位為$K)
https://imgur.com/a/nxAP3nG
※ 編輯: treefrog (101.9.98.23 臺灣), 06/26/2019 15:45:09
→ Pieteacher: Try plt.semilogy() 06/26 18:54