简体   繁体   中英

Polar contour plot in Bokeh or Plotly

I need to draw a contour plot using either Bokeh or Plotly Python to show the wave distribution in a circle shape area. There are always 49 points I studied and the x_cord and y_cord are known and not change in different cases. The wave density (z) can be calculated from other function in python and changes case by case.

I searched online and cannot find a solution. Is there anyone familiar with Bokeh/Plotly that can help on this?

The picture I want to draw looks like this: 在此处输入图片说明

Thanks!

Here are the input x_cord, y_cord and an example of z

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]

z = [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]

In plotly you can get something like that: 等高线图

Code:
# import the necessaries libraries
import plotly.offline as py
import plotly.graph_objs as go
# Create data
data = [
    go.Histogram2dcontour(
          x = [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 = [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],
          z = [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],
         # You can choose another colorscale if you want
         #[‘Blackbody’,‘Bluered’,‘Blues’,‘Earth’,‘Electric’,‘Greens’,‘Greys’,\
         # ‘Hot’,‘Jet’,‘Picnic’,‘Portland’,‘Rainbow’,‘RdBu’,‘Reds’,‘Viridis’,
         # ‘YlGnBu’,‘YlOrRd’]
         colorscale='Portland',
         contours=dict(
            coloring='heatmap',
            start=3,
            end=9,
            size=1
         ),
    )
]
# Layout usually need to set the title, size of plot etc.
layout = go.Layout(
    height = 600,
    width = 600,
    bargap = 0,
    hovermode = 'closest',
    showlegend = False)
# Create fig
fig = go.Figure(data=data,layout=layout)
# Save the plot in your Python script directory and open in a browser
py.plot(fig, filename='contoursimple.html')

For additional information about how to plot contour plot correctly you can visit plotly documentation at this page and this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM