Changing axis parameters for polar regions in Matplotlib / Python

I have a problem replacing axis labels in Matplotlib. I want to change the parameters of the radial axis on my polar graph.

Basically, I calculate the cylinder distortion, which is nothing but the radius deviates from the original (perfectly circular) cylinder. Some of the distortion values ​​are negative, while some of them are positive due to tensile and compressive forces. I'm looking for a way to represent this in cylindrical coordinates graphically, so I thought the best option would be a polar plot. Excel gives me a "radar chart" that is flexible enough so that I can specify the minimum and maximum values ​​of the radial axis. I want to reproduce this in Python using Matplotlib.

My Python script for building on polar coordinates is as follows.

#!usr/bin/env python import matplotlib.pyplot as plt import numpy as np x = np.arange(-180.0,190.0,10) theta = (np.pi/180.0 )*x # in radians offset = 2.0 R1 = [-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\ -0.137,-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\ -0.137,-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\ -0.137,-0.358] fig1 = plt.figure() ax1 = fig1.add_axes([0.1,0.1,0.8,0.8],polar=True) ax1.set_rmax(1) ax1.plot(theta,R1,lw=2.5) 

My plot is as follows: bad

But I do not want to imagine it. I want to change my radial axis so that I can show the data as a deviation from some reference value, say -2. How can I ask Matplotlib to change the label of the minimum axis in polar coordinates? I can do it VERY easily in Excel. I select a minimum radial value of -2 to get the following Excel radar chart:
excelplot

In Python, I can easily compensate for my input by 2. My new dataset is called R2, as shown:

 #!usr/bin/env python import matplotlib.pyplot as plt import numpy as np x = np.arange(-180.0,190.0,10) theta = (np.pi/180.0 )*x # in radians offset = 2.0 R2 = [1.642,1.517,1.521,1.654,1.879,2.137,2.358,2.483,2.479,2.346,2.121,1.863,\ 1.642,1.517,1.521,1.654,1.879,2.137,2.358,2.483,2.479,2.346,2.121,1.863,1.642,\ 1.517,1.521,1.654,1.879,2.137,2.358,2.483,2.479,2.346,2.121,1.863,1.642] fig2 = plt.figure() ax2 = fig2.add_axes([0.1,0.1,0.8,0.8],polar=True) ax2.plot(theta,R2,lw=2.5) ax2.set_rmax(1.5*offset) plt.show() 

The graph is shown below: good

As soon as I get this, I TOGETHER add axis labels and write it to my script. But this is a really ugly way. Is there any way that I can directly get the Matplotlib equivalent of an Excel radar chart and change the axis label labels without having to manipulate my input?

+4
source share
1 answer

You can simply use the usual way to set the axis limits:

 #!usr/bin/env python import matplotlib.pyplot as plt import numpy as np x = np.arange(-180.0,190.0,10) theta = (np.pi/180.0 )*x # in radians offset = 2.0 R1 = [-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\ -0.137,-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\ -0.137,-0.358,-0.483,-0.479,-0.346,-0.121,0.137,0.358,0.483,0.479,0.346,0.121,\ -0.137,-0.358] fig1 = plt.figure() ax1 = fig1.add_axes([0.1,0.1,0.8,0.8],polar=True) ax1.set_ylim(-2,2) ax1.set_yticks(np.arange(-2,2,0.5)) ax1.plot(theta,R1,lw=2.5) 
+7
source

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


All Articles