✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
📊 Dash 2.0 is Arriving. Register here.

Adding windrose charts to subplots in plotly dashboard

Hello,

I am attempting to create a dashboard in Plotly using the ‘make_subplots’ function from plotly.tools.

from plotly.tools import make_subplots
template = make_subplots(rows = 4,
                         cols = 4, 
                         specs = [[{'colspan':4}, None, None, None],
                                  [{'colspan':4}, None, None, None],
                                  [{}, {}, {'colspan': 2, 'rowspan': 2}, None],
                                  [{}, {}, None, None]]
                        )

To add bar charts and scatter plots it’s straightforward;

template.append_trace(bar_chart, 1, 1)

But when attempting to add my wind rose chart in the same way I get the following error;


ValueError Traceback (most recent call last)
in ()
5 }})
6 ‘’’
----> 7 template.append_trace(tokyo_windrose, 3,1)
8 pyoff.iplot(template)

/anaconda3/lib/python3.6/site-packages/plotly/basedatatypes.py in append_trace(self, trace, row, col)
1182 “”", DeprecationWarning)
1183
-> 1184 self.add_trace(trace=trace, row=row, col=col)
1185
1186 def _set_trace_grid_position(self, trace, row, col):

/anaconda3/lib/python3.6/site-packages/plotly/basedatatypes.py in add_trace(self, trace, row, col)
1029 return self.add_traces(data=[trace],
1030 rows=[row] if row is not None else None,
-> 1031 cols=[col] if col is not None else None
1032 )[0]
1033

/anaconda3/lib/python3.6/site-packages/plotly/basedatatypes.py in add_traces(self, data, rows, cols)
1112 if rows is not None:
1113 for trace, row, col in zip(data, rows, cols):
-> 1114 self._set_trace_grid_position(trace, row, col)
1115
1116 # Make deep copy of trace data (Optimize later if needed)

/anaconda3/lib/python3.6/site-packages/plotly/basedatatypes.py in _set_trace_grid_position(self, trace, row, col)
1219 "An axis object for ({r},{c}) subplot "
1220 “cell got deleted.”.format(r=row, c=col))
-> 1221 trace[‘xaxis’] = ref[0]
1222 trace[‘yaxis’] = ref[1]
1223

/anaconda3/lib/python3.6/site-packages/plotly/basedatatypes.py in setitem(self, prop, value)
2730 # ### Validate prop ###
2731 if prop not in self._validators:
-> 2732 self._raise_on_invalid_property_error(prop)
2733
2734 # ### Get validator for this property ###

/anaconda3/lib/python3.6/site-packages/plotly/basedatatypes.py in _raise_on_invalid_property_error(self, *args)
2910 full_obj_name=full_obj_name,
2911 invalid_str=invalid_str,
-> 2912 prop_descriptions=self._prop_descriptions))
2913
2914 def update(self, dict1=None, **kwargs):

ValueError: Invalid property specified for object of type plotly.graph_objs.Area: ‘xaxis’

Is it possible to add wind rose charts to the subplots in a dashboard?

That one is for #api:python

Hi @charlie.plot,

Unfortunately the make_subplots command doesn’t support polar plots right now. See https://github.com/plotly/plotly.py/issues/758. Feel free to give this issue a thumbs-up to help inform out priorities in the future.

In the meantime, here’s an example of creating subplots without the make_subplots function.


It’s a bit more verbose, but also more flexible and this approach works with all trace types. To set the domain of the polar subplot you would use fig.layout.polar.domain.

Hope that helps get you started!
-Jon

Okay, so I’ve been exploring the ‘domain’ route of getting wind rose charts as subplots. From what I can tell, to use fig.layout.polar.domain you need to assign each chart a name using the ‘subplot’ label like in the example here; https://plot.ly/python/polar-chart/#categorical-polar-chart

However when I tried that with my wind rose plots I get this error.

ValueError: Invalid property specified for object of type plotly.graph_objs.Area: ‘subplot’

Valid properties:
    customdata
        Assigns extra data each datum. This may be useful when
        listening to hover, click and selection events. Note
        that, "scatter" traces also appends customdata items in
        the markers DOM elements
    customdatasrc
        Sets the source reference on plot.ly for  customdata .
    hoverinfo
        Determines which trace information appear on hover. If
        `none` or `skip` are set, no information is displayed
        upon hovering. But, if `none` is set, click and hover
        events are still fired.
    hoverinfosrc
        Sets the source reference on plot.ly for  hoverinfo .
    hoverlabel
        plotly.graph_objs.area.Hoverlabel instance or dict with
        compatible properties
    ids
        Assigns id labels to each datum. These ids for object
        constancy of data points during animation. Should be an
        array of strings, not numbers or any other type.
    idssrc
        Sets the source reference on plot.ly for  ids .
    legendgroup
        Sets the legend group for this trace. Traces part of
        the same legend group hide/show at the same time when
        toggling legend items.
    marker
        plotly.graph_objs.area.Marker instance or dict with
        compatible properties
    name
        Sets the trace name. The trace name appear as the
        legend item and on hover.
    opacity
        Sets the opacity of the trace.
    r
        For legacy polar chart only.Please switch to
        "scatterpolar" trace type.Sets the radial coordinates.
    rsrc
        Sets the source reference on plot.ly for  r .
    selectedpoints
        Array containing integer indices of selected points.
        Has an effect only for traces that support selections.
        Note that an empty array means an empty selection where
        the `unselected` are turned on for all points, whereas,
        any other non-array values means no selection all where
        the `selected` and `unselected` styles have no effect.
    showlegend
        Determines whether or not an item corresponding to this
        trace is shown in the legend.
    stream
        plotly.graph_objs.area.Stream instance or dict with
        compatible properties
    t
        For legacy polar chart only.Please switch to
        "scatterpolar" trace type.Sets the angular coordinates.
    tsrc
        Sets the source reference on plot.ly for  t .
    uid

    visible
        Determines whether or not this trace is visible. If
        "legendonly", the trace is not drawn, but can appear as
        a legend item (provided that the legend itself is
        visible).

I’m starting to think that there is no functionality for getting wind rose charts (like the one on this page) in subplots - I can’t find a single example online and have been playing round with it myself for hours. :frowning: I did however get my scattergeo working in a subplot though which was some progress!

Hi @charlie.plot,

I see what mean. The trouble you’re running into is the the Area trace is an old trace type that doesn’t use the new polar framework that’s used by scatterpolar. Fortunately, we just released the successor, the barpolar trace. This was released in plotly.py 3.3.0 last week.

The documentation for the Wind Rose example itself should be updated to use barpolar very soon. In the mean time, check out the release notebook I put together for the 3.3.0 release (https://github.com/jonmmease/plotly.py_release_notebooks/blob/master/notebooks/v3.3.0/v3.3.0.ipynb). barpolar traces have the subplot parameter just like scatterpolar, so they can be subplotted just like the scatterpolar traces in https://plot.ly/python/polar-chart/#categorical-polar-chart.

Hope that helps!
-Jon