Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render charts in Databricks using Plotly?

I am trying to render charts using Plotly library in Databricks. However, no image is rendered. I use for example this statement:

from plotly.offline import init_notebook_mode, iplot
from plotly import graph_objs as go

    # Initialize plotly
    init_notebook_mode(connected=True)

    daily_df=df

    def plotly_df(df, title=''):
        """Visualize all the dataframe columns as line plots."""
        common_kw = dict(x=df.index, mode='lines')
        data = [go.Scatter(y=df[c], name=c, **common_kw) for c in df.columns]
        layout = dict(title=title)
        fig = dict(data=data, layout=layout)
        iplot(fig, show_link=False)

    plotly_df(daily_df)

There is no output. Why?

like image 259
LaLaTi Avatar asked Oct 26 '25 19:10

LaLaTi


1 Answers

If you use plotly version 4.2, you no longer need to import plotly.offline and you can just call fig.show() on your figure created with Plotly Express or go.Figure(). The new renderer framework has a Databricks-specific renderer :)

Full documentation here: https://plot.ly/python/renderers/ and https://plot.ly/python/creating-and-updating-figures/

like image 71
nicolaskruchten Avatar answered Oct 28 '25 18:10

nicolaskruchten