【问题标题】:Why is my degree argument behaving weirdly?为什么我的学位论点表现得很奇怪?
【发布时间】:2019-03-12 13:51:45
【问题描述】:

这就是我正在运行的代码

#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,但问题仍然存在。 度数参数是度数还是其他(弧度)?如果这不是问题,我做错了什么?

【问题讨论】:

    标签: python matplotlib polar-coordinates


    【解决方案1】:

    您必须以弧度传递角度。此外,您的身高只有 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])
    

    【讨论】:

    • 感谢您的回答。它有帮助。关于高度,我确实将其设为 5,但并未将其转换为弧度(?)。它仍然是 5,即条形的高度。
    • @Abhishek:您是否像我一样使用heights = [math.radians(5)]?还要检查 y 轴范围
    • 不,我只是使用代码中的简单列表。我没有改变它。我想没关系。如果它没有坏,不要修理它,是吗?是的,我调整了 y 轴限制以满足我的需要
    猜你喜欢
    • 2021-10-11
    • 2018-09-09
    • 2014-07-03
    • 2014-02-05
    • 2023-01-07
    • 2023-01-10
    • 2015-09-14
    • 1970-01-01
    • 2019-07-16
    相关资源
    最近更新 更多