question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

filled contour plot in plotly.express

See original GitHub issue

Is there a way to create filled contour plots with plotly.express similar to the following one? contour2 (reference: https://plot.ly/python/contour-plots/)

The only ones I have seen so far with plotly.express are not filled, e.g.:

import plotly.express as px
df = px.data.iris()
fig = px.density_contour(df, x="sepal_width", y="sepal_length", color="species", marginal_x="rug", marginal_y="histogram")
fig.show()

contour1 (reference: https://plot.ly/python/plotly-express/)

Any help is appreciated! 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
lucanicscommented, Jan 16, 2020

In case this is useful to anyone, I needed this kind of plot in combination with animation frames.

Although the solution below might not be very beautiful using the iris dataset, you might have a better usecase for other dataframes:

import plotly.express as px
df = px.data.iris()
df_w = df["sepal_width"].copy()
df_l = df["sepal_length"].copy()

fig = px.density_contour(df, x="sepal_width", y="sepal_length", 
                         range_x=[df_w.min(),df_w.max()], 
                         range_y = [df_l.min(), df_l.max()],
                         animation_frame="species")

fig.data[0]["contours"].coloring = "fill"
fig.update_traces(colorscale="Viridis")

for num,frames in enumerate(fig.frames, start=0):
    fig.frames[num].data[0]["contours"].coloring = "fill"

fig.show()
2reactions
nicolaskruchtencommented, Jan 16, 2020

You can set the colorscale in the update_traces() call like this:

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Contour plots in Python - Plotly
A 2D contour plot shows the contour lines of a 2D numerical array z , i.e. interpolated lines of isovalues of z ....
Read more >
Contour Plots using Plotly in Python - GeeksforGeeks
A contour plot has a function of two variables of curves along which the function has constant values so that these curves join...
Read more >
Plotly.Express.Density_contour - Linux Hint
A density contour refers to a 2d histogram resembling a contour plot but is computed by grouping a set of data points as...
Read more >
plotly.graph_objects.Contour — 5.11.0 documentation
fillcolor – Sets the fill color if contours.type is “constraint”. Defaults to a half-transparent variant of the line color, marker color, or marker...
Read more >
Plotly: how to fill the background of a contour ... - Stack Overflow
Some plot types have the connectgaps=True option to fill in the gaps but this does not seem to be available for the Histogram2dContour...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found