Python matplotlib
Providing data
Double-click on the following file to replace it with your own or upload a new file by dragging it into this window.
Inspecting your data
Reference uploaded files with the Cmd/Ctrl+E shortcut inside a code cell.
import pandas as pddata = pd.read_csv(OpenNEX-chicago-climate.csv)data.head(100)2.1s
Python
Plotting your data using matplotlib
import pandas as pdimport matplotlibimport matplotlib.pyplot as plt# Read in the CSVdata = pd.read_csv(OpenNEX-chicago-climate.csv)# Specify categorical datafor col in ['Model', 'Scenario', 'Variable']: data[col] = data[col].astype('category')# Coax date strings to beginning of year datesdata['Year'] = data['Date'] \ .astype('datetime64') \ .map(lambda d: "%d-01-01" % d.year) \ .astype('datetime64')# Convert temperatures from Kelvin to Celsiusdata['Temperature'] = data['Value'] - 273.15# Get max temperature and group by year and scenariomax_per_year = data \ .groupby(['Year', 'Scenario']) \ .max(numeric_only=True) \ .loc[:,'Temperature']groups = max_per_year.reset_index().set_index('Year').groupby('Scenario')# Plot all groups and set up label for legend to usefig, ax = plt.subplots(figsize=(8,6),dpi=100)for key, group in groups: ax.plot(group.index, group['Temperature'], label=key)# Add legend to plotplt.legend()# Set axis labels and titlemodel = data.loc[1, 'Model']ax.set( title="Maximum mean temperature for warmest month using model %s" % model, xlabel="Year", ylabel="Temperature [Celsius]")plt.show()2.3s
Python