Reputation: 1467
I'm trying to replicate a certain plot using matplotlib: it should look something like this.
I have seen that it it possible to use the PolarAxes to draw radial points: for istance i've made a really simple polar plot 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:
So my question is: is there a way to draw the lines as in the first figure, and to adjust the width in order to fit in the whole circonference? Also some hints on how to handle the colors would be much appreciated.
UPDATE: the data that has to be plotted is quite simple: each track is an array of floats whose range is between 0 and 9 (and the color is derived from the colormap RdYlGn). The array length are multiple of 96.
UPDATE 2: that's the snipped that i have 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)
Upvotes: 5
Views: 6763
Reputation: 2825
Without more information about how your data is organized it is difficult to say what the best way to recreate this plot would be. It is easy to draw lines of different widths and colors on a polar plot. Though if you need as many as in your example, things may get slow. I have also provided 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)
Upvotes: 9