matplotlib的标准间隔为45°。 如何将此间隔更改为15°? 所以我从下面的图片开始
到这张图片
问题是我找不到合适的文档。 这是当前使用的代码:
#Define arrays
def processDir(file, output, title):
angles=list()
values=list()
lines = [line.rstrip('\n') for line in open(file)]
for line in lines: # Iterate lines
stringElement = str.split(line, " ") # Split elements
angle = int(stringElement[0])
value = float(stringElement[1])
angles.append((angle/360)*2*3.1415926)
values.append(value)
ax = plt.subplot(111, projection='polar')
plt.polar(angles, values, label=title, color="darkviolet")
ax.legend(bbox_to_anchor=(0., 1.1, -1., .102), loc=3,
ncol=2, mode="expand", borderaxespad=0., frameon=False)
ax.grid(True)
axmin = ax.get_rmin()
axmax = ax.get_rmax()
#Zorg ervoor dat de stap 6dB per lijn is
step = 6
# generate new ticklist with desired step size
axlist = np.arange(axmin, axmax + step, step)
# set new ticks
ax.set_rticks(axlist)
ax.figure.set_size_inches(8, 5)
plt.savefig(output)
plt.show()
processDir("test.txt", "no output", "My Title")
使用textfile:
0 54.3
15 54.4
30 54.2
45 54.2
60 54.4
75 54.8
90 55.6
120 56.3
150 57.5
180 57
210 56.8
240 56.8
270 57.4
300 57.1
330 57.2
360 54.3
答案 0 :(得分:0)
您应该始终提供Minimal, Complete, and Verifiable example,否则问题可能会暂停 幸运的是,我记得your previous question。您也可以在极坐标图中调整x-ticks。使用您之前的示例代码:
def processDir(file, output, title):
angles=list()
values=list()
lines = [line.rstrip('\n') for line in open(file)]
for line in lines: # Iterate lines
stringElement = str.split(line, " ") # Split elements
angle = int(stringElement[0])
value = float(stringElement[1])
angles.append((angle/360)*2*3.1415926)
values.append(value)
ax = plt.subplot(111, projection='polar')
plt.polar(angles, values, label=title, color="darkviolet")
#here we set the xticks to 24 values, i.e. 15°
ax.set_xticks(np.linspace(0, 2 * np.pi, 24, endpoint = False))
ax.text(-0.4, 0.3, 'Test\nTest', horizontalalignment = 'center', verticalalignment = 'center', transform = ax.transAxes)
ax.legend(bbox_to_anchor=(0., 1.1, 1., .102), loc=3,
ncol=2, mode="expand", borderaxespad=0., frameon=False)
ax.grid(True)
ax.figure.set_size_inches(8, 5)
plt.show()
processDir("test.txt", "no output", "My Title")
回顾上一个问题,你可以同样解决以前的问题:
ax.set_yticks(np.linspace(0, 60, 11))
如果我们也将其整合,输出将是: