以下のようなcsvデータ(KKtest.csv)を気温グラフにしたいのですが、エラーが出てしまいました。どの箇所を変更したらよいでしょうか。。。
ヘッダー部分は漢字で読み込ませ、凡例を漢字で表示させたいです。
またx軸には時間を表示させたいです。
Time,東,西,南,南北,北,北東 1:00,27,27.4,27.7,27.4,27.3,27.2 2:00,26.8,27.1,27.5,27.4,27,26.9 3:00,26.6,27,27.3,27,26.8,26.6 4:00,26.5,26.7,27,26.7,26.6,26.4 5:00,26.5,26.7,26.9,26.7,26.5,26.3 6:00,27.4,27.4,28.2,28.1,27.6,26.6 7:00,28.4,28.6,30.5,30.9,30,27.9 8:00,30.4,30.4,32.7,33,32.4,29.6 9:00,30.3,31.7,34.4,34,34,32 10:00,30.7,32.4,34.3,34.6,34.3,33.8 11:00,31.7,32.4,32.8,34.2,35.3,34.6 12:00,32,33.3,34,34.6,34.1,34.5 13:00,30.9,33.7,34.2,34.4,33.9,35 14:00,31.6,33.3,33.8,33.5,33.8,34.9 15:00,30.9,33.3,33.6,33,33.2,34 16:00,30.5,32.8,33.1,32.3,32.4,34.1 17:00,29.4,31.3,31.8,31.3,32,33 18:00,28.6,29.8,30.4,29.9,30.6,31.9 19:00,27.9,29.1,29.3,29.3,29.6,30.7 20:00,27.4,28.3,28.5,28.7,28.9,29.6 21:00,27.3,28.4,28.3,28.5,28.6,29 22:00,27.1,28.1,28,28.3,28.3,28.6 23:00,27.2,27.7,27.8,27.9,28,28.1 0:00,26.9,27.8,27.7,27.7,27.7,27.6
import pandas as pd from matplotlib import pyplot as plt df = pd.read_csv('KKtest81.csv',encoding="utf-8",header=0) df["Time"] = pd.to_datetime(df["Time"]) start_datetime = df.iloc[0]["Time"] end_datetime = df.iloc[0]["Time"] title_label = start_datetime.strftime("%d") df.plot() ## 気温グラフ plt.title('Temperature Aug_01 @Kanagawa') plt.xlabel('Time') plt.ylabel('Temperature[℃]') plt.grid(axis='y',c='gainsboro', zorder=9) plt.savefig('KK8.1.png', bbox_inches="tight") plt.show()
エラー
ValueError: view limit minimum -36854.182916666665 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units <Figure size 432x288 with 1 Axes>
CSVファイルが Shiftjis でなくてエラーが発生しているのでは?
回答3件
あなたの回答
tips
プレビュー