So this the code I'm running
#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()
So, I have used 45 as the degree parameter but the bar gets printed at 58 degrees? Entering 90 gives puts the bar at 115-ish. I have tried using linspace
as well and the problem persists.
Is the degree parameter in degrees or is it something else(radians)? If that's not the problem, what am I doing wrong?
You have to pass the angles in radians. Moreover, your height is only 5 degrees which is 0.087 radians. Then you are setting your y-limits from 0 to 7 radians. Such a low height is not visible on this scale. Therefore, you need to either remove ax1.set_ylim(0, 7.0)
and use a smaller upper y-limit like 0.1 for example.
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])