Can this polar chart be used in Dash?

I’m new to Plot.ly Would like to use this in dash open source:

Is that possible? It’s not exactly clear to me how or whether code like this has to be altered when placed in a dash app file.

Thanks

Hi @david-bethesda

Here you have an example using the same info:

import dash_html_components as html
import dash
import plotly.graph_objs as go
import pandas as pd
import dash_core_components as dcc

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/hobbs-pearson-trials.csv")



fig = {"data": [go.Scatterpolargl(r = df.trial_1_r, theta = df.trial_1_theta, name = "Trial 1", 
                                     marker=dict(size=15, color="mediumseagreen")),
                   go.Scatterpolargl(r = df.trial_2_r, theta = df.trial_2_theta, name = "Trial 2", 
                                     marker=dict(size=20, color="darkorange")),
                   go.Scatterpolargl(r = df.trial_3_r, theta = df.trial_3_theta, name = "Trial 3",
                                     marker=dict(size=12, color="mediumpurple")),
                   go.Scatterpolargl(r = df.trial_4_r, theta = df.trial_4_theta, name = "Trial 4",
                                     marker=dict(size=22, color = "magenta")),
                   go.Scatterpolargl(r = df.trial_5_r, theta = df.trial_5_theta, name = "Trial 5",
                                     marker=dict(size=19, color = "limegreen")),
                   go.Scatterpolargl(r = df.trial_6_r, theta = df.trial_6_theta, name = "Trial 6",
                                     marker=dict(size=10, color = "gold"))],
        
       "layout": go.Layout(title = "Hobbs-Pearson Trials", font_size = 15, showlegend = False, 
                           polar = dict(bgcolor = "rgb(223, 223, 223)", angularaxis = dict(linewidth = 3, showline=True, linecolor='black'),
                                        radialaxis = dict(side = "counterclockwise", showline = True, linewidth = 2, gridcolor = "white", 
                                                          gridwidth = 2,)), paper_bgcolor = "rgb(223, 223, 223)")}


app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Graph(figure=fig)
])


if __name__ == '__main__':
    app.run_server(debug=True)

image

The only think I do not know how to add is:

fig.update_traces(mode="markers", marker=dict(line_color='white', opacity=0.7))

But it could be not so difficult. :thinking:

1 Like

There are so many ways you can accomplish this. Here’s a basic reference implementation you could use as a starting point:

from dash.dash import Dash
import plotly.graph_objects as go
import dash
import dash_html_components as html
import dash_core_components as dcc

app = Dash(__name__)



fig = go.Figure(go.Barpolar(
    r=[3.5, 1.5, 2.5, 4.5, 4.5, 4, 3],
    theta=[65, 15, 210, 110, 312.5, 180, 270],
    width=[20,15,10,20,15,30,15,],
    marker_color=["#E4FF87", '#709BFF', '#709BFF', '#FFAA70', '#FFAA70', '#FFDF70', '#B6FFB4'],
    marker_line_color="black",
    marker_line_width=2,
    opacity=0.8
))

fig.update_layout(
    template=None,
    polar = dict(
        radialaxis = dict(range=[0, 5], showticklabels=False, ticks=''),
        angularaxis = dict(showticklabels=False, ticks='')
    )
)


app.layout = html.Div(
    dcc.Graph(figure=fig)

)

if __name__ == "__main__":
    app.run_server()

Here’s how it looks for me:

1 Like