为什么我的学位论证表现得很奇怪?

问题描述 投票:1回答:1

所以这就是我正在运行的代码

#Pass Sonar
import numpy as np
import matplotlib.pyplot as plt

#Entering Data 

# angles of all the passes
theta = [45]

heights = [5]
# length of all the passes


# Getting axes handles/objects
ax1 = plt.subplot(111, polar=True)

# Plot
bars = ax1.bar(theta, heights,
           color='xkcd:orangered',
           #color=plt.cm.jet(heights),
           width=0.1,
           #width=heights,
           bottom=0.0,
           edgecolor='k',
           alpha=0.5,
           label='All Passes>2 mts')
##Main tweaks
# Radius limits
ax1.set_ylim(0, 7.0)
# Radius ticks
ax1.set_yticks(np.linspace(0, 7.0, 8))
# Radius tick position in degrees
ax1.set_rlabel_position(315)
#Angle ticks
ax1.set_xticks(np.linspace(0, 2.0*np.pi, 9)[:-1])


#Additional tweaks
plt.grid(True)
plt.legend()
plt.title("Pass Sonar: Mesut Özil v/s Leicester City - 22.10.2018")

plt.show()

所以,我使用45作为度数参数,但是条形图打印在58度?输入90给出了115-ish。我也尝试过使用linspace,问题仍然存在。度数参数是度数还是其他(弧度)?如果这不是问题,我做错了什么? That's roughly 57-58 degrees

python matplotlib polar-coordinates
1个回答
2
投票

你必须以弧度传递角度。而且,你的身高只有5度,即0.087弧度。然后,您将y限制设置为0到7弧度。在这种规模上看不到如此低的高度。因此,您需要删除ax1.set_ylim(0, 7.0)并使用较小的上限y限制,例如0.1。

import numpy as np
import matplotlib.pyplot as plt
import math

# angles of all the passes
theta = [math.radians(45)]

heights = [math.radians(5)]
# length of all the passes

# Getting axes handles/objects
ax1 = plt.subplot(111, polar=True)

# Plot
bars = ax1.bar(theta, heights,
           color='xkcd:orangered',
           #color=plt.cm.jet(heights),
           width=0.1,
           #width=heights,
           bottom=0.0,
           edgecolor='k',
           alpha=0.5,
           label='All Passes>2 mts')
##Main tweaks
# Radius limits
ax1.set_ylim(0, 0.1)
ax1.set_rlabel_position(315)
#Angle ticks
ax1.set_xticks(np.linspace(0, 2.0*np.pi, 9)[:-1])

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.