plotly / plotly_express

Plotly Express - Simple syntax for complex charts. Now integrated into plotly.py!
https://plot.ly/python/plotly-express/
MIT License
5 stars 1 forks source link

Using px.density_contour with both marginal_x and contours_coloring causes error #175

Open adamerose opened 3 years ago

adamerose commented 3 years ago

I get the error below when trying to add marginal_x to the "continuously-colored and labeled" example on this page https://plotly.com/python/2d-histogram-contour/

import plotly.express as px

df = px.data.tips()

fig = px.density_contour(df, x="total_bill", y="tip", marginal_x='box')
fig.update_traces(contours_coloring="fill", contours_showlabels=True)
"C:\Program Files\Python38\python.exe" D:/_MyFiles/Programming/scratch/scratch.py
Traceback (most recent call last):
  File "D:/_MyFiles/Programming/scratch/scratch.py", line 6, in <module>
    fig.update_traces(contours_coloring="fill", contours_showlabels=True)
  File "C:\Program Files\Python38\lib\site-packages\plotly\basedatatypes.py", line 1376, in update_traces
    trace.update(patch, overwrite=overwrite, **kwargs)
  File "C:\Program Files\Python38\lib\site-packages\plotly\basedatatypes.py", line 5067, in update
    BaseFigure._perform_update(self, kwargs, overwrite=overwrite)
  File "C:\Program Files\Python38\lib\site-packages\plotly\basedatatypes.py", line 3862, in _perform_update
    raise err
ValueError: Invalid property specified for object of type plotly.graph_objs.Box: 'contours'

...

Bad property path:
contours_coloring
^^^^^^^^
john-verran commented 1 year ago

@adamerose did you ever find a solution or workaround for this?

adamerose commented 1 year ago

@john-verran Nope haven't revisited this since I first made the issue, it's a pretty specific graph and I haven't personally had the need to find a workaround.

But in general when I run into a roadblock with plotly express for something important the workaround is to rebuild it from scratch using the base Plotly API, it's never failed me before but takes more effort. I would start here https://plotly.com/python/contour-plots/ and then add the histograms with shared axes like this https://plotly.com/python/subplots/#subplots-with-shared-xaxes