# Heatmap in polar coordinates

#1

I want to make a heatmap graph in polar coordinate. There is many examples with scaterplotpolar, but nothing to make polar graph with other graphs types.
Is this supported ?

#2

@ghislainp Polar heatmap is not supported at the moment. It makes sense to plot such a heatmap when you intend to map your data to a cyclical colorscale, according to their polar angle. In this case you should use a circular colorscale such as `hsv` or `phase` (from matplotlib cmocean). See the attached images.

Here is an example of polar heatmap:
https://plot.ly/~empet/13959. If you are interested in this type of heatmap, and your data is in cartesian coordinates, drop here a message and I’ll post a jupyter notebook illustrating how to define it.

HSV colorscale:

phase colorscale:

#3

@empet Hi empet, I’m new to Plotly and I need to draw this type of Polar heatmap in my work. I searched around but I didn’t find how to do it in Plotly. It would be very appreciated if you could show how to do it.

Here is my data:
x_cord = [0, -0.0, -34.6, -49, -34.6, 0.0, 34.6, 49, 34.6, -0.0, -37.5, -69.3, -90.5, -98, -90.5, -69.3, -37.5, 0.0, 37.5, 69.3, 90.5, 98, 90.5, 69.3, 37.5, -0.0, -38.0, -73.5, -103.9, -127.3, -142.0, -147, -142.0, -127.3, -103.9, -73.5, -38.0, 0.0, 38.0, 73.5, 103.9, 127.3, 142.0, 147, 142.0, 127.3, 103.9, 73.5, 38.0]
y_cord = [0, 49, 34.6, -0.0, -34.6, -49, -34.6, 0.0, 34.6, 98, 90.5, 69.3, 37.5, -0.0, -37.5, -69.3, -90.5, -98, -90.5, -69.3, -37.5, 0.0, 37.5, 69.3, 90.5, 147, 142.0, 127.3, 103.9, 73.5, 38.0, -0.0, -38.0, -73.5, -103.9, -127.3, -142.0, -147, -142.0, -127.3, -103.9, -73.5, -38.0, 0.0, 38.0, 73.5, 103.9, 127.3, 142.0]

The x_cord and y_cord are fixed all the time and we want to draw the Polar heapmap for this circle shape wafer.
The z values are calculated from other code and an example is as follow:
z_value = [0.932, 0.93, 0.93, 0.932, 0.933, 0.933, 0.932, 0.931, 0.93, 0.924, 0.925, 0.926, 0.927, 0.928, 0.929, 0.929, 0.929, 0.93, 0.929, 0.928, 0.927, 0.926, 0.925, 0.924, 0.924, 0.92, 0.92, 0.921, 0.922, 0.923, 0.923, 0.924, 0.925, 0.924, 0.924, 0.925, 0.925, 0.924, 0.923, 0.921, 0.92, 0.921, 0.92, 0.919, 0.919, 0.917, 0.917, 0.918, 0.919]

Thanks!

#4

Hi @fengjie08,
Welcome to Plotly!

To be able to plot a heatmap within a disk of radius R, first you should define a grid on the rectangle
[-R, R] x[R, R], and mask the outside of the disk:

``````N = 300
R=1
x = np.linspace(-R,R, N)
y = np.linspace(-R,R, N)
X,Y = np.meshgrid(x,y)

disk = X**2+Y**2
I, J = np.where(disk>R)
z = X*Y**2-X**3*np.sin(X-Y)
z[I, J] = None # mask the outside of the disk of center (0,0)   and radius R

trace = dict(type='heatmap',
x=x,
y=y,
z=z, #note that z has the shape of X,Y, not x, y as in your example!!!!!!!!!!
colorscale='YlGnBu',
showscale=True,
colorbar=dict(thickness=20,
ticklen=4,
tickfont=dict(size=10)))

layout = dict(title='Polar heatmap',
width=450,
height=450,
showlegend=False,
xaxis=dict(visible=False),
yaxis=dict(visible=False)
)
``````

Here is the corresponding Figure:

Your posted data don’t meet this requirement. I plotted your points (x,y) as a scatter plot and noticed that they lie on a few concentric circles.

In the above example my z-values aren’t periodic in the polar angle. If your data are periodic then you should use a cyclic colorscale like hsv, or the new twilight colorscale:

``````pl_hsv = [[0.0, 'rgb(0, 242, 242)'],#S=1, V=0.95,
[0.083, 'rgb(0, 121, 242)'],
[0.166, 'rgb(0, 0, 242)'],
[0.25, 'rgb(121, 0, 242)'],
[0.333, 'rgb(242, 0, 242)'],
[0.416, 'rgb(242, 0, 121)'],
[0.5, 'rgb(242, 0, 0)'],
[0.583, 'rgb(242, 121, 0)'],
[0.666, 'rgb(242, 242, 0)'],
[0.75, 'rgb(121, 242, 0)'],
[0.833, 'rgb(0, 242, 0)'],
[0.916, 'rgb(0, 242, 121)'],
[1.0, 'rgb(0, 242, 242)']]
``````
``````pl_twilight = [[0.0, 'rgb(225, 216, 225)'],
[0.053, 'rgb(202, 209, 215)'],
[0.105, 'rgb(164, 190, 202)'],
[0.158, 'rgb(128, 165, 195)'],
[0.211, 'rgb(106, 140, 190)'],
[0.263, 'rgb(96, 110, 184)'],
[0.316, 'rgb(94, 79, 172)'],
[0.368, 'rgb(90, 46, 147)'],
[0.421, 'rgb(76, 23, 107)'],
[0.474, 'rgb(54, 16, 66)'],
[0.526, 'rgb(55, 17, 57)'],
[0.579, 'rgb(86, 21, 70)'],
[0.632, 'rgb(120, 31, 79)'],
[0.684, 'rgb(151, 52, 79)'],
[0.737, 'rgb(173, 78, 80)'],
[0.789, 'rgb(189, 111, 90)'],
[0.842, 'rgb(199, 142, 113)'],
[0.895, 'rgb(207, 176, 154)'],
[0.947, 'rgb(218, 203, 198)'],
[1.0, 'rgb(225, 216, 225)']]
``````

This is an example of polar heatmap with z values periodic in the polar angle:

#5

Hi @empot, thank you very much for the help! I think I can interpolate z_value matrix into a X, Y meshgrid, and then follow your code to generate the heatmap I need. I am trying to implement this idea, but I have a quick question:

What is the code to generate the first polar heatmap in your previous respond? In detail: you defined trace and layout as following:
trace = dict(type = ‘heatmap’, x=x, …)
layout = dict(title = ‘Polar heatmap’, …)
What is the code following this to generate the heatmap?

Thank you very much!

#6

@fengjie08, There is no code affter the trace and layout definition. The two lists, `pl_hsv` and `pl_twilight` are cyclic colorscale. `pl_hsv` is illustrated in my answer to the question posted by gislainp, above.