• Overview
    • English (Global)
    • 日本語 (Japan)
  • Control Theory
  • Python
  • TwinCAT
  • Profile
  • Training
    • English (Global)
    • 日本語 (Japan)
  • English (Global)
  • 日本語 (Japan)
  1. Python
  2. Python library: pylib-sakata
  3. Function manual of plot
  • Python

    • Environment Setup
      • How to create a Python virtual environment
      • Python IDE Installation Guide

    • Python library: pylib-sakata
      • Setup of pylib-sakata
      • Function manual of ctrl
      • Function manual of fft
      • Function manual of meas
      • Function manual of traj
      • Function manual of plot
      • Function manual of init

    • Simulation
      • Precise Time-Domain Simulation of High-Order LTI Systems

On this page

  • pylib_sakata.plot
    • plot_xy
    • plot_tf
    • plot_tffrd
    • plot_nyquist
    • plot_nyquist_assistline
    • makefig
    • savefig
    • showfig
    • closefig
  1. Python
  2. Python library: pylib-sakata
  3. Function manual of plot

Function manual of plot

pylib_sakata.plot

plot_xy

pylib_sakata.plot.plot_xy(ax, x, y, styl=‘-’, col=‘b’, width=1.5, alpha=1.0, xrange=None, yrange=None, xlabel=None, ylabel=None, legend=None, loc=‘best’, title=None, xscale=‘linear’, yscale=‘linear’, labelouter=True)

This function is for drawing a 2-D figure from x and y data. You can select xy scale in linear type, log type and so on.

  • Parameters:
    • ax: handle of axis
    • x: 1-D array data of x-axis
    • y: 1-D array data of y-axis
    • styl: line style (Optional), Default: ‘-’, Select in ‘-’ (solid), ‘–’ (dashed), ‘.’ (dotted), ‘-.’ (dashdot)
    • col: line color (Optional), Default: ‘b’ (blue)
    • width: line width (Optional), Default: 1.5
    • alpha: transmittance of line, Default: 1.0, set from 0 to 1.0
    • xrange: plot range of x-axis (Optional), Default: None, set as [xmin, xmax]
    • yrange: plot range of y-axis (Optional), Default: None, set as [ymin, ymax]
    • xlabel: label of x-axis (Optional), Default: None, set strings data
    • ylabe: label of y-axis (Optional), Default: None, set strings data
    • legend: legend of data, Default: None, set a list of strings data
    • loc: location of the legend, Default: ‘best’, Detail
    • title: title of figure (Optional), Default: None, set strings data
    • xscale: scale type of x-axis (Optional), Default: ‘linear’, set in ‘linear’, ‘log’, …
    • labelouter: only display outer label of xy-axes, Default: True
  • Returns:
    • None

Examples

fig1 = plot.makefig()
ax1 = fig1.add_subplot(311)
ax2 = fig1.add_subplot(312)
ax3 = fig1.add_subplot(313)
plot.plot_xy(ax1, t, chirp, '-', 'm', 0.5, 1.0, [0, 50], [-3.0, 3.0], ylabel='Input [N]', legend='Chirp', title='Time response')
plot.plot_xy(ax2, tout, u, '-', 'b', 0.5, 1.0, [0, 50], [-3.0, 3.0], ylabel='Input [N]', legend='Servo Out')
plot.plot_xy(ax3, tout, y*1.0e3, '-', 'b', 0.5, 1.0, [0, 50], [-0.3, 0.3], xlabel='Time [s]', ylabel='Output [mm]', legend='Position')

fig2 = plot.makefig()
ax1 = fig2.add_subplot(311)
ax2 = fig2.add_subplot(312)
ax3 = fig2.add_subplot(313)
plot.plot_xy(ax1, fft_axis, chirp_fft, '-', 'm', 1.5, 1.0, freqrange, [0, 1.0], ylabel='Input [N]', legend='Chirp', title='Power spectrum density', xscale='log')
plot.plot_xy(ax2, fft_axis, u_fft, '-', 'b', 1.5, 1.0, freqrange, [0, 0.1], ylabel='Input [N]', legend='Servo Out', xscale='log')
plot.plot_xy(ax3, fft_axis, y_fft*1.0e6, '-', 'b', 1.5, 1.0, freqrange, [0, 20], xlabel='Frequency [Hz]', ylabel='Output [um]', legend='Position', xscale='log')

plot_tf

pylib_sakata.plot.plot_tf(ax_mag, ax_phase, sys, freq, styl=‘-’, col=‘b’, width=1.5, alpha=1.0, freqrange=None, magrange=None, legend=None, loc=‘best’, title=None, labelouter=True)

This function is for drawing a Bode diagram from a LTI model.

  • Parameters:
    • ax_mag: handle of magnitude axis
    • ax_phase: handle of phase axis, if you set as None, phase axis is skipped.
    • sys: LTI model (StateSpace or TransferFunction)
    • freq: 1-D array frequency data [Hz]
    • styl: line style (Optional), Default: ‘-’, Select in ‘-’ (solid), ‘–’ (dashed), ‘.’ (dotted), ‘-.’ (dashdot)
    • col: line color (Optional), Default: ‘b’ (blue)
    • width: line width (Optional), Default: 1.5
    • alpha: transmittance of line, Default: 1.0, set from 0 to 1.0
    • freqrange: plot range of frequency-axis (Optional), Default: None, set as [freqmin, freqmax]
    • magrange: plot range of magnitude-axis (Optional), Default: None, set as [magmin, magmax]
    • legend: legend of data, Default: None, set a list of strings data
    • loc: location of the legend, Default: ‘best’, Detail
    • title: title of figure (Optional), Default: None, set strings data
    • labelouter: only display outer label of xy-axes, Default: True
  • Returns:
    • None

Examples

# Sensitivity function
fig1 = plot.makefig()
ax_mag = fig1.add_subplot(111)
ax_phase = None
plot.plot_tf(ax_mag, ax_phase, S, freq, '-', 'm', 1.5, 1.0, legend='Measurement', title='Frequency response of sensitivity function')
plot.plot_tf(ax_mag, ax_phase, Sn, freq, '--', 'b', 1.5, 1.0, [1, 1000], [-60, 10], legend='Model')

# Complementary sensitivity function
fig2 = plot.makefig()
ax_mag = fig2.add_subplot(211)
ax_phase = fig2.add_subplot(212)
plot.plot_tf(ax_mag, ax_phase, T, freq, '-', 'm', 1.5, 1.0, legend='Measurement', title='Frequency response of complementary sensitivity function')
plot.plot_tf(ax_mag, ax_phase, Tn, freq, '--', 'b', 1.5, 1.0, [1, 1000], [-60, 10], legend='Model')

plot_tffrd

pylib_sakata.plot.plot_tffrd(ax_mag, ax_phase, freqresp, styl=‘-’, col=‘b’, width=1.5, alpha=1.0, freqrange=None, magrange=None, legend=None, loc=‘best’, title=None, labelouter=True, ax_coh=None, coh=None)

This function is for drawing a Bode diagram from a frequency response data.

  • Parameters:
    • ax_mag: handle of magnitude axis
    • ax_phase: handle of phase axis, if you set as None, phase axis is skipped.
    • freqresp: instance of FreqResp class
    • styl: line style (Optional), Default: ‘-’, Select in ‘-’ (solid), ‘–’ (dashed), ‘.’ (dotted), ‘-.’ (dashdot)
    • col: line color (Optional), Default: ‘b’ (blue)
    • width: line width (Optional), Default: 1.5
    • alpha: transmittance of line, Default: 1.0, set from 0 to 1.0
    • freqrange: plot range of frequency-axis (Optional), Default: None, set as [freqmin, freqmax]
    • magrange: plot range of magnitude-axis (Optional), Default: None, set as [magmin, magmax]
    • legend: legend of data, Default: None, set a list of strings data
    • loc: location of the legend, Default: ‘best’, Detail
    • title: title of figure (Optional), Default: None, set strings data
    • labelouter: only display outer label of xy-axes, Default: True
    • ax_coh: handle of coherence axis, Default: None
    • coh: 1-D array coherence data, Default: None
  • Returns:
    • None

Examples

# Plant
fig1 = plot.makefig()
ax_mag = fig.add_subplot(311)
ax_phase = fig.add_subplot(312)
ax_coh = fig.add_subplot(313)
plot.plot_tffrd(ax_mag, ax_phase, Pmeas_frd, '-', 'm', 1.5, 1.0, ax_coh=ax_coh, coh=coh, legend='Measurement', title='Frequency response of plant')
plot.plot_tffrd(ax_mag, ax_phase, Pnz_frd, '--', 'b', 1.5, 1.0, freqrange, legend='Model')

# Sensitivity function
fig2 = plot.makefig()
ax_mag = fig1.add_subplot(111)
ax_phase = None
plot.plot_tffrd(ax_mag, ax_phase, S_frd, '-', 'm', 1.5, 1.0, legend='Measurement', title='Frequency response of sensitivity function')
plot.plot_tffrd(ax_mag, ax_phase, Sn_frd, '--', 'b', 1.5, 1.0, [1, 1000], [-60, 10], legend='Model')

# Complementary sensitivity function
fig3 = plot.makefig()
ax_mag = fig2.add_subplot(211)
ax_phase = fig2.add_subplot(212)
plot.plot_tffrd(ax_mag, ax_phase, T_frd, '-', 'm', 1.5, 1.0, legend='Measurement', title='Frequency response of complementary sensitivity function')
plot.plot_tffrd(ax_mag, ax_phase, Tn_frd, '--', 'b', 1.5, 1.0, [1, 1000], [-60, 10], legend='Model')

plot_nyquist

pylib_sakata.plot.plot_nyquist(ax, freqresp, styl=‘-’, col=‘b’, width=1.5, alpha=1.0, xrange=None, yrange=None, legend=None, loc=‘best’, title=None, labelouter=True)

This function is for drawing a Nyquist diagram from a frequency response data of a open loop system

  • Parameters:
    • ax: handle of axis
    • freqresp: instance of FreqResp class
    • styl: line style (Optional), Default: ‘-’, Select in ‘-’ (solid), ‘–’ (dashed), ‘.’ (dotted), ‘-.’ (dashdot)
    • col: line color (Optional), Default: ‘b’ (blue)
    • width: line width (Optional), Default: 1.5
    • alpha: transmittance of line, Default: 1.0, set from 0 to 1.0
    • xrange: plot range of real-axis (Optional), Default: None, set as [realmin, realmax]
    • yrange: plot range of imaginary-axis (Optional), Default: None, set as [imagmin, imagmax]
    • legend: legend of data, Default: None, set a list of strings data
    • loc: location of the legend, Default: ‘best’, Detail
    • title: title of figure (Optional), Default: None, set strings data
    • labelouter: only display outer label of xy-axes, Default: True
  • Returns:
    • None

Examples

fig = plot.makefig()
ax = fig.add_subplot(111)
plot.plot_nyquist(ax, G_frd, '-', 'm', 1.5, 1.0, legend='Measurement', title='Nyquist Diagram')
plot.plot_nyquist(ax, Gn_frd, '--', 'b', 1.5, 1.0, legend='Model')

plot_nyquist_assistline

pylib_sakata.plot.plot_nyquist_assistline(ax)

This function is for drawing assist line of a Nyquist diagram.

  • Parameters:
    • ax: handle of axis
  • Returns:
    • None

Examples

plot.plot_nyquist_assistline(ax)

makefig

pylib_sakata.plot.makefig(dpi=100, figsize=(6, 4), popwin=False)

This function will make a new figure handle.

  • Parameters:
    • dpi: dot per inch of figure (Optional), Default: 100
    • figsize: set figure size (Optional), Default: (6, 4) which means 600x400 pixels
    • popwin: switch to fix the popup window of the figure (Optional), Default: False
  • Returns:
    • fig: figure handle

Examples

fig = plot.makefig()

savefig

pylib_sakata.plot.savefig(figName)

This function will save a current figure.

  • Parameters:
    • figName: figure name for saving a current figure, set strings data
  • Returns:
    • None

Examples

plot.savefig('freq_P.png')

showfig

pylib_sakata.plot.showfig()

This function will call matplotlib.pyplot.show()

Examples

showfig()

closefig

pylib_sakata.plot.closefig(fig)

This function will call matplotlib.pyplot.close(fig)

Examples

closefig(fig)

© 2026 Koichi Sakata

Built with Quarto

  • Privacy Policy