简体   繁体   中英

Polar axis not showing data (matplotlib)

This is my first time in drawing a polar axis plot with matplotlib and would appreciate some guidance here. I am currently trying to plot a line at theta1 (105 degrees) but I am unable to see any data printed on my polar axis plot. The image I obtained is as shown:

在此输入图像描述

My script is:

import matplotlib as mpl
mpl.use('Agg')
import numpy as np
import matplotlib.pyplot as plt


fig1 = plt.figure()
ax1 = fig1.add_axes([0,0,1,1],polar=True)
theta1 = 105.968
print ("theta1= %s" %theta1)    
R1 = 1

ax1.plot(theta1, R1, lw=2.5)

plt.savefig('plot.png')

Can anyone advise me on what I am doing incorrectly? As I've used ax1.plot(theta1, R1, lw=2.5) , I expected a straight line to appear at around 106 degrees, with the line extending out at 1.0, and line width of 2.5. I've also tried to double the line width.

Two problems here:

  • First has nothing to do with polar plots. Providing a single value to the first two arguments of plot creates a point, not a line. You would need to set some marker, marker="o" , to see this point.

    A line needs at least two points to be shown as line.

     ax.plot([x1,x2],[y1,y2]) 
  • Second, angles need to be given in radiants.

     theta = np.deg2rad([105,105]) R = [0,1] ax.plot(theta, R, lw=2.5) 

在此输入图像描述

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