Skip to content

Polar Contour #2973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cdhainaut opened this issue Dec 14, 2020 · 4 comments
Closed

Polar Contour #2973

cdhainaut opened this issue Dec 14, 2020 · 4 comments

Comments

@cdhainaut
Copy link

Hi everyone,

I am looking for a possibility to do polar contour plots with plotly.
I saw this was mentioned in this topic already by @rafa-guedes : #2024
But I need a more complete solution.
The ideal contour plot I want should look like this:
no_scale

If I use the method described in the post I mentioned, this gives me this result:
image

Which isn't matching enough the level of details I want to have.

Do you have an idea of a workaround I could use to achieve the target ?

Thanks

Cheers

@empet
Copy link

empet commented Dec 14, 2020

@carlitador
Polar Contour plot can be defined in a similar way as a rectangular (quadratic) one, but invalidating z-values outside a disk.
Let us suppose we have z-data stored in an array of shape (n, n). To plot its polar contour proceed as follows:

  • define:
x = np.linspace(-r, r, n)  #r =disk radius
X, Y = np.meshgrid(x, x)
z[np.where(X**2+Y**2>r**2)] = np.nan   
fig=go.Figure(go.Contour(x=x, y=x, z=z, colorscale="balance", line_width=0.5,
                         contours=dict(start=np.nanmin(z),  end=np.nanmax(z), size=0.3)))
fig.update_layout(width=600, height=600,
                             template="none", xaxis_visible=False, yaxis_visible=False)
fig.show()

polar-contour-plot

The above plot was defined from a npy file storing my z-data having np.nan outside the disk, centered at 0 and of radius 2, i.e:

z = np.load("circular-data.npy", allow_pickle=True) #https://github.com/empet/Datasets/blob/master/circular-data.npy
x = np.linspace(-2,  2,  420)
fig=go.Figure(go.Contour(x=x, y=x, z=z, colorscale="balance", line_width=0.5,
                         contours=dict(start=np.nanmin(z), end=np.nanmax(z), size=0.3)))
fig.update_layout(width=600, height=600,
                  template="none",xaxis_visible=False, yaxis_visible=False)

@cdhainaut
Copy link
Author

Hi @empet,
Its a good idea of a workaround. However, I need to have the radius and angle ticks and axis appearing on the chart. Any idea of how to include that properly ?

Thanks

@empet
Copy link

empet commented Dec 15, 2020

@carlitador
For contour it is sufficient to plot the radius marking the angle 0, more radii cover the contour information. To display angles in degrees, as annotations, see this old tutorial and adapt it to the Plotly 4.14:
https://chart-studio.plotly.com/~empet/14803. You can also set customdata for your contour; consisting in r=np.sqrt(X**2+Y**2), and theta=np.arctan2(Y, X)*180/np.pi. Then define hovertemplate, i.e a string containing description of the hover text for each point in your contour: https://chart-studio.plotly.com/~empet/15366.

@gvwilson
Copy link
Contributor

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants