我在 Excel 中有資料。并且這個資料包含了1996-2010的資訊,你可以查看enter image description here你可以看到一些資料。(總共有68000個資料)。但是當我嘗試繪制它時 1996-1998-2000....2010 寫在 x 軸上。在此處輸入影像描述我希望它寫下所有年份 1996-1997-1998-1999- ... 2009-2010。你能幫忙嗎?這是我的代碼:
import numpy as np
import pandas as pd
import datetime
import matplotlib.pyplot as plt
df=pd.read_excel("Julian_iski_data_python.xlsx")
b2_station= df[ ( df["prSM [db]"] == 1) & ( df["Station"] == "B2" ) ]
k0_station= df[ ( df["prSM [db]"] == 1) & ( df["Station"] == "K0" ) ]
m8_station= df[ ( df["prSM [db]"] == 1) & ( df["Station"] == "M8" ) ]
m14_station= df[ ( df["prSM [db]"] == 1) & ( df["Station"] == "M14" ) ]
m23_station= df[ ( df["prSM [db]"] == 1) & ( df["Station"] == "M23" ) ]
my2_station= df[ ( df["prSM [db]"] == 1) & ( df["Station"] == "MY2" ) ]
b2_years= b2_station["yyyy-mm-dd hh:mm:ss.sss"]
b2_temperature= b2_station["T(degC)"]
k0_years= k0_station["yyyy-mm-dd hh:mm:ss.sss"]
k0_temperature= k0_station["T(degC)"]
m8_years = m8_station["yyyy-mm-dd hh:mm:ss.sss"]
m8_temperature= m8_station["T(degC)"]
m14_years = m14_station["yyyy-mm-dd hh:mm:ss.sss"]
m14_temperature= m14_station["T(degC)"]
m23_years = m23_station["yyyy-mm-dd hh:mm:ss.sss"]
m23_temperature= m23_station["T(degC)"]
my2_years = my2_station["yyyy-mm-dd hh:mm:ss.sss"]
my2_temperature= my2_station["T(degC)"]
fig = plt.figure(figsize=(10,10))
axes = fig.add_axes([0.04,0.06,0.95,0.91])
axes.plot(b2_years,b2_temperature,"ro",label="B2")
axes.plot(k0_years,k0_temperature,"b^",label="K0")
axes.plot(m8_years,m8_temperature,"gs",label="M8")
axes.plot(m23_years,m23_temperature,"md",label="M23")
axes.plot(my2_years,my2_temperature,"c*",label="MY2")
axes.set_xlabel("Time")
axes.set_ylabel("Temperature")
axes.legend()
axes.xaxis.grid()
plt.show()
uj5u.com熱心網友回復:
請試試:
import numpy as np
import pandas as pd
import datetime
import seaborn as sns
import matplotlib.dates as md
df=pd.read_excel("Julian_iski_data_python.xlsx")
df = df[["prSM [db]", "Station", "yyyy-mm-dd hh:mm:ss.sss", "T(degC)"]]
df = df.loc[df["prSM [db]"] == 1]
df = df.loc[df["Station"].isin(["B2", "K0", "M8", "M14", "M23", "MY2"])]
fig = plt.figure(figsize=(10,10))
axes = fig.add_axes([0.04,0.06,0.95,0.91])
sns.lineplot(data=df, x="yyyy-mm-dd hh:mm:ss.sss", y="T(degC)", hue="Station")
axes.xaxis.set_major_locator(md.YearLocator(1,month=1,day=1))
查看樣式示例
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/506358.html
標籤:Python 擅长 数据库 数据框 matplotlib