0
パンダでデータフレームの2つの列をプロットするとき、どのように日付形式を変更できますか?例えばパンダでデータフレームの2つの列を互いにプロットするときの日付形式を変更
は、私が実行した場合:
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
np.random.seed(1)
dates = pd.date_range('1/1/2000', periods=50)
print('dates: {0}'.format(dates))
df = pd.DataFrame(np.random.randn(len(dates), 1), index=dates, columns=['A'])
print('df: {0}'.format(df))
plt.figure(figsize=(60,15))
df.plot(y='A', use_index=True)
plt.xticks(rotation=70)
plt.savefig('plot.png', dpi=300, bbox_inches='tight')
は私が取得:
にはどうすればxticksに表示される日付の形式を制御することができますか?
以下のように、日付を文字列にキャストする必要がありますか、それとも解決策がありますか?
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
np.random.seed(1)
dates = pd.date_range('1/1/2000', periods=50)
print('dates: {0}'.format(dates))
# I have just changed the line below to introduce `.astype(str)`:
df = pd.DataFrame(np.random.randn(len(dates), 1), index=dates.astype(str), columns=['A'])
print('df: {0}'.format(df))
plt.figure(figsize=(60,15))
df.plot(y='A', use_index=True)
plt.xticks(rotation=70)
plt.savefig('plot2.png', dpi=300, bbox_inches='tight')