Python控制包 - 提高奈奎斯特绘图的分辨率

时间:2015-06-28 19:16:56

标签: python matplotlib

我正在使用Python控制模块绘制传输函数的Bode和Nyquist图。代码简单如下:

# Simple Nyquist plotting

import control
import matplotlib.pyplot as plt

num = 5
den = [1,6,11,6]

#Creating a transfer function G = num/den
G = control.tf(num,den) 

control.nyquist(G)
plt.grid(True)
plt.title('Nyquist Diagram of G(s) = 5/(s+1)(s+2)(s+3)')
plt.xlabel('Re(s)')
plt.ylabel('Im(s)')
plt.show()

绘制了奈奎斯特图: enter image description here

我想知道是否有可能增加点数图表,提高其分辨率。

2 个答案:

答案 0 :(得分:2)

请注意,在图中, all 存在数据点。你只需要放大窗口,你就会看到所有的点。

您可以手动执行此操作(只需放大绘图窗口),也可以set the plot window in Matplotlib显示结果:

If you've already got the figure created you can quickly do this:

fig = matplotlib.pyplot.gcf()
fig.set_size_inches(18.5, 10.5)
fig.savefig('test2png.png', dpi=100)

要将大小更改传播到现有的gui窗口,请添加forward = True

fig.set_size_inches(18.5, 10.5, forward=True)

答案 1 :(得分:0)

python-control库遵循类似matlab的语法,因此最好首先检查是否可以像在matlab中那样进行。这一次确实如此。您实际上可以查看提示的函数签名。

例如,如果我们输入

,则在IPython终端中
cnt.nyquist? 

我们得到了

Signature: cnt.nyquist(syslist, omega=None, Plot=True, color='b', labelFreq=0, *args, **kwargs)
Docstring:
Nyquist plot for a system

Plots a Nyquist plot for the system over a (optional) frequency range.

Parameters
----------
syslist : list of Lti
    List of linear input/output systems (single system is OK)
omega : freq_range
    Range of frequencies (list or bounds) in rad/sec
Plot : boolean
    If True, plot magnitude
labelFreq : int
    Label every nth frequency on the plot
*args, **kwargs:
    Additional options to matplotlib (color, linestyle, etc)

Returns
-------
real : array
    real part of the frequency response array
imag : array
    imaginary part of the frequency response array
freq : array
    frequencies

Examples
--------
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> real, imag, freq = nyquist_plot(sys)
File:      c:\python34\lib\site-packages\control\freqplot.py
Type:      function

因此,对于您的情况,修复

很简单
num = 5
den = [1,6,11,6]

#Creating a transfer function G = num/den
G = control.tf(num,den) 
w = numpy.logspace(-3,3,5000)
control.nyquist(G,w);