2
次のプロットを示す次のコードがあります。会計年度をx軸に正しく表示することができず、あたかもフロートしているかのように表示されます。 astype(int)
を実行しようとしましたが動作しませんでした。私が間違っていることに関するアイデアは? Matplotlibは整数ではなく軸上に浮動小数値
次のプロットを示す次のコードがあります。会計年度をx軸に正しく表示することができず、あたかもフロートしているかのように表示されます。 astype(int)
を実行しようとしましたが動作しませんでした。私が間違っていることに関するアイデアは? Matplotlibは整数ではなく軸上に浮動小数値
は必ず整数だけの場所がticklabelを得るようにするために、あなたが引数として整数でmatplotlib.ticker.MultipleLocator
を使用することがあります。
p1 = plt.bar(list(asset['FISCAL_YEAR']),list(asset['TOTAL']),align='center')
plt.show()
この
はプロットです。軸の数値をフォーマットするには、matplotlib.ticker.StrMethodFormatter
を使用します。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker
df = pd.DataFrame({"FISCAL_YEAR" : np.arange(2000,2017),
'TOTAL' : np.random.rand(17)})
plt.bar(df['FISCAL_YEAR'],df['TOTAL'],align='center')
locator = matplotlib.ticker.MultipleLocator(2)
plt.gca().xaxis.set_major_locator(locator)
formatter = matplotlib.ticker.StrMethodFormatter("{x:.0f}")
plt.gca().xaxis.set_major_formatter(formatter)
plt.show()