Python Plotly
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.0s
Python
Plotting your data using Plotly
import pandas as pdimport plotly.graph_objs as goimport 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 'name' for legend to useplot_data = [{ 'x': group.index, 'y': group['Temperature'], 'name': key} for key, group in groups]# Set axis labels and titlemodel = data.loc[1, 'Model']layout = { 'title': 'Maximum mean temperature for warmest month using model %s' % model, 'xaxis': {'title': 'Year'}, 'yaxis': {'title': 'Temperature [Celsius]'}}# Returning the figure tells Nextjournal to display itgo.Figure(data=plot_data, layout=layout)3.2s
Python