如何使用python使用此数据绘制图形?
我想使用一年中每个月的最高、最低和平均温度创建时间序列图。我建议查看不同类型的数据,这些数据可以使用quick如何使用python使用此数据绘制图形?,python,plot,graph,Python,Plot,Graph,我想使用一年中每个月的最高、最低和平均温度创建时间序列图。我建议查看不同类型的数据,这些数据可以使用quickpip3 install matplotlib安装 以下是一些入门代码,您可以使用这些代码熟悉库: # Import the library import matplotlib.pyplot as plt # Some sample data to play around with temps = [30,40,45,50,55,60] months = ["Jan"
pip3 install matplotlib安装
以下是一些入门代码,您可以使用这些代码熟悉库:
# Import the library
import matplotlib.pyplot as plt
# Some sample data to play around with
temps = [30,40,45,50,55,60]
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
# Create a figure and plot the data
plt.figure()
plt.plot(temps)
# Add labels to the data points (optional)
for i, point in enumerate(months):
plt.annotate(point, (i, temps[i]))
# Apply some labels
plt.ylabel("Temperature (F)")
plt.title("Temperature Plot")
# Hide the x axis labels
plt.gca().axes.get_xaxis().set_visible(False)
# Show the comlpeted plot
plt.show()
您能说得更具体一点吗?plz,有一个名为matplotlib的绘图库,您已经试过了吗?
# import libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# sample data
df = pd.DataFrame({'Date':pd.date_range('2010-01-01', '2010-12-31'),
'Temp':np.random.randint(20, 100, 365)})
df.head()
Date Temp
0 2010-01-01 95
1 2010-01-02 20
2 2010-01-03 22
3 2010-01-04 26
4 2010-01-05 93
# group by month and get min, max, mean values for temperature
temp_agg = df.groupby(df.Date.dt.month)['Temp'].agg([min, max, np.mean])
temp_agg.index.name='month'
temp_agg
min max mean
month
1 20 99 50.258065
2 25 98 56.642857
3 22 89 51.225806
4 22 98 60.333333
5 27 99 57.645161
6 21 99 62.000000
7 20 98 67.419355
8 36 98 63.806452
9 22 99 62.166667
10 24 99 63.322581
11 22 97 64.200000
12 20 99 60.870968
# shorthand method of plotting entire dataframe
temp_agg.plot()