Published :
February 9, 2024

Creating Plots within Google Sheets

Launch early and often! Last week we introduced advanced features to Neptyne for Google Sheets, allowing you to read and write cells from your custom functions or the REPL.

Today we’re announcing plotting and image support for google sheets. While sheets has built in plotting, you’re quite limited both in plot types and configuration options. When combining with popular Python libraries like Plotly an Matpotlib anything is possible.

To see how it works, let’s create a polar bar chart. You can follow along by pasting the following code into your editor:


import plotly.express as px

def wind_data():
    return px.data.wind()

def wind_plot(data):
    df = data.to_dataframe()
    return px.bar_polar(
        df,
        r="frequency",
        theta="direction",
        color="strength",
        color_discrete_sequence=px.colors.sequential.Plasma_r,
    )

From the REPL, run

A1 = wind_data()

to load some sample data of wind speeds, directions and frequencies from Laurel, NE into our spreadsheet.

Next inside cell E1, paste:

=Py("wind_plot", A1:C129)

This will automatically create a chart above the E1 cell.

Now let’s update the data. Change C2 to 4 to create a clear outlier in the data, and you’ll notice the chart updates automatically!

All sorts of other chart types are possible such as this sankey diagram of government spending or map of NYC subway stations. For a more detailed walkthrough, head to our plotting tutorial