Matplotlib: draw a series of radial lines on PolarAxes

I am trying to reproduce a specific plot using matplotlib: it should look something like this.

Final plot

I saw that you can use PolarAxes to draw radial points: for istance, I made a really simple polar graph with the following snippet:

import matplotlib.pyplot as plt fig = plt.figure() # Set the axes as polar ax = fig.add_subplot(111, polar=True) # Draw some points ax.plot([0],[1], 'o') ax.plot([3],[1], 'o') ax.plot([6],[1], 'o') # Go clockwise ax.set_theta_direction(-1) # Start from the top ax.set_theta_offset(1.570796327) plt.savefig('test.png') 

And I get something like this:

First example

So my question is: is there a way to draw lines, as in the first picture, and adjust the width to fit into the whole zircon? Some tips on how to handle colors would also be very helpful.

UPDATE: the data that needs to be built is quite simple: each track is an array of floats, the range of which is in the range from 0 to 9 (and the color is obtained from the RdYlGn color map). The length of the array is a multiple of 96.

UPDATE 2: which was disabled, what I used

 # mydata is a simple list of floats a = np.array([[x for i in range(10)] for x in mydata]) # construct the grid radius = np.linspace(0.2,0.4,10) theta = np.linspace(0,2*np.pi,len(a)) R,T = np.meshgrid(radius,theta) fig = plt.figure() ax = fig.add_subplot(111, polar = True) # plot the values using the appropriate colormap ax.pcolor(T,R,a,cmap=cm.RdYlGn) 
+4
source share
1 answer

Without additional information about how your data is organized, it's hard to say what is the best way to recreate this plot. In the polar region, it is easy to draw lines of various widths and colors. Although, if you need as much as in your example, everything can become slow. I also gave an example of a polar pseudo-color plot.

 import numpy as np import matplotlib.pyplot as plt #Create radius and theta arrays, and a 2d radius/theta array radius = np.linspace(0.2,0.4,51) theta = np.linspace(0,2*np.pi,51) R,T = np.meshgrid(radius,theta) #Calculate some values to plot Zfun = lambda R,T: R**2*np.cos(T) Z = Zfun(R,T) #Create figure and polar axis fig = plt.figure() ax = fig.add_subplot(111, polar = True) ax.pcolor(T,R,Z) #Plot calculated values #Plot thick red section and label it theta = np.linspace(0,np.pi/4,21) ax.plot(theta,[1.23 for t in theta],color='#AA5555',linewidth=10) #Colors are set by hex codes ax.text(np.pi/8,1.25,"Text") ax.set_rmax(1.25) #Set maximum radius #Turn off polar labels ax.axes.get_xaxis().set_visible(False) ax.axes.get_yaxis().set_visible(False) 

Plot

+6
source

Source: https://habr.com/ru/post/1438694/


All Articles