MCPcopy Create free account
hub / github.com/Klipper3d/klipper / plot_frequency

Function plot_frequency

scripts/graph_accelerometer.py:102–134  ·  view source on GitHub ↗
(datas, lognames, max_freq)

Source from the content-addressed store, hash-verified

100 return pdata, bins, t
101
102def plot_frequency(datas, lognames, max_freq):
103 calibration_data = calc_freq_response(datas[0], max_freq)
104 for data in datas[1:]:
105 calibration_data.add_data(calc_freq_response(data, max_freq))
106 freqs = calibration_data.freq_bins
107 psd = calibration_data.psd_sum[freqs <= max_freq]
108 px = calibration_data.psd_x[freqs <= max_freq]
109 py = calibration_data.psd_y[freqs <= max_freq]
110 pz = calibration_data.psd_z[freqs <= max_freq]
111 freqs = freqs[freqs <= max_freq]
112
113 fig, ax = matplotlib.pyplot.subplots()
114 ax.set_title("\n".join(wrap(
115 "Frequency response (%s)" % (', '.join(lognames)), MAX_TITLE_LENGTH)))
116 ax.set_xlabel('Frequency (Hz)')
117 ax.set_ylabel('Power spectral density')
118
119 ax.plot(freqs, psd, label='X+Y+Z', alpha=0.6)
120 ax.plot(freqs, px, label='X', alpha=0.6)
121 ax.plot(freqs, py, label='Y', alpha=0.6)
122 ax.plot(freqs, pz, label='Z', alpha=0.6)
123
124 ax.xaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
125 ax.yaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
126 ax.grid(which='major', color='grey')
127 ax.grid(which='minor', color='lightgrey')
128 ax.ticklabel_format(axis='y', style='scientific', scilimits=(0,0))
129
130 fontP = matplotlib.font_manager.FontProperties()
131 fontP.set_size('x-small')
132 ax.legend(loc='best', prop=fontP)
133 fig.tight_layout()
134 return fig
135
136def plot_compare_frequency(datas, lognames, max_freq, axis):
137 fig, ax = matplotlib.pyplot.subplots()

Callers 1

mainFunction · 0.85

Calls 3

calc_freq_responseFunction · 0.85
plotMethod · 0.80
add_dataMethod · 0.45

Tested by

no test coverage detected