Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置步长极坐标图matplotlib python_Python_Matplotlib_Plot_Pycharm - Fatal编程技术网

设置步长极坐标图matplotlib python

设置步长极坐标图matplotlib python,python,matplotlib,plot,pycharm,Python,Matplotlib,Plot,Pycharm,目前我正在matplotlib中绘制极坐标图。 非强制性的步长是10,如下所示。 如何将步长更改为6而不是10? 最小值和最大值需要自动保持不变,就像现在一样。 我试过了maxlags,但没能成功 有了这行代码,我需要自动设置范围,这是不可能的,因为我有很多极坐标图 ax.set_rmax(2) ax.set_rticks([0.5, 1, 1.5, 2]) 也 不起作用 下面是当前使用的代码 import matplotlib import os import matplotlib.pyp

目前我正在matplotlib中绘制极坐标图。 非强制性的步长是10,如下所示。 如何将步长更改为6而不是10? 最小值和最大值需要自动保持不变,就像现在一样。 我试过了maxlags,但没能成功

有了这行代码,我需要自动设置范围,这是不可能的,因为我有很多极坐标图

ax.set_rmax(2)
ax.set_rticks([0.5, 1, 1.5, 2]) 

不起作用

下面是当前使用的代码

import matplotlib
import os
import matplotlib.pyplot as plt

#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)

    # Plot values

    ax = plt.subplot(111, projection='polar')

    # Deze maakt 6 graden
    # ax.set_yticks(range(0, 60, 6), minor=False)  # Define the yticks



    plt.polar(angles, values, label=title, color="darkviolet")


    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.savefig(output)
    plt.show()

folder = "mapje"
for filename in os.listdir(folder):
    if filename.endswith(".txt"):
        inputPath = os.path.join(folder, filename)
        bareName = os.path.splitext(filename)[0]
        outputPath = os.path.join(folder, bareName+".pdf")
        title = "dB waarde terts " + bareName
        processDir(inputPath, outputPath, title)
在名为mapje的文件夹中使用文本文件“1kHz”:

0 54.3
5 54.4
10 54.2
15 54.4
20 54.6
25 54.4
30 54.2
35 54.4
40 54.1
45 54.2
50 54.4
55 54.5
60 54.4
65 54.5
70 54.5
75 54.8
80 55.2
85 55.3
90 55.6
95 55.6
100 55.6
105 55.9
110 56.5
115 56.3
120 56.3
125 56.3
130 56.6
135 56.8
140 57
145 57.1
150 57.5
155 57.5
160 57.5
165 57.5
170 57.2
175 57.1
180 57
185 56.2
190 56.6
195 56.5
200 56.6
205 56.9
210 56.8
215 56.7
220 56.9
225 57.1
230 57
235 57
240 56.8
245 57.1
250 57.1
255 57
260 57.3
265 57.3
270 57.4
275 57.3
280 57.4
285 57.3
290 57.1
295 57.2
300 57.1
305 57.1
310 57.1
315 57.3
320 57.2
325 57.3
330 57.2
335 57.3
340 56.9
345 57
355 56.8
360 54.3

一种方法是:

import numpy as np
#retrieve automatically generated axis values
axmin = ax.get_rmin()
axmax = ax.get_rmax()
step = 6
#generate new ticklist with desired step size
axlist = np.arange(axmin, axmax + step, step)
#set new ticks
ax.set_rticks(axlist) 
输出


请随时提供一份,以备将来参考。在您的情况下,“最小”是关键-我们不需要这个问题的所有细节,您如何加载文件。坚持这一点,将始终提高获得好答案的机会。
import numpy as np
#retrieve automatically generated axis values
axmin = ax.get_rmin()
axmax = ax.get_rmax()
step = 6
#generate new ticklist with desired step size
axlist = np.arange(axmin, axmax + step, step)
#set new ticks
ax.set_rticks(axlist)