QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_pyplot.h
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#ifndef QWT_PYPLOT_H
11#define QWT_PYPLOT_H
12
13#include "qwt_global.h"
14#include "qwt_symbol.h"
15
16#include <qobject.h>
17#include <qcolor.h>
18#include <qpen.h>
19#include <qstring.h>
20#include <qvector.h>
21
22class QPointF;
23class QRectF;
24class QwtFigure;
25class QwtPlot;
26class QwtPlotCurve;
27class QwtPlotBarChart;
29class QwtPlotBoxChart;
34class QwtPlotGrid;
35class QwtPlotMarker;
36class QwtPlotZoneItem;
39class QwtBoxSample;
40class QwtOHLCSample;
41
56struct QWT_EXPORT QwtFormatString
57{
58 QColor color;
60 Qt::PenStyle lineStyle = Qt::SolidLine;
61 bool hasColor = false;
62 bool hasMarker = false;
63 bool hasLineStyle = false;
64 bool noLine = false;
65
66 // Parse a matplotlib format string
67 static QwtFormatString parse(const QString& fmt);
68};
69
112class QWT_EXPORT QwtPyPlot : public QObject
113{
114 Q_OBJECT
115
116public:
117 // Construct from a QwtFigure (multi-subplot mode)
118 explicit QwtPyPlot(QwtFigure* figure, QObject* parent = nullptr);
119
120 // Construct from a single QwtPlot (single-plot mode)
121 explicit QwtPyPlot(QwtPlot* plot, QObject* parent = nullptr);
122
123 ~QwtPyPlot() override;
124
125 // ---- State management ----
126
127 // Get the current figure (like matplotlib's gcf)
128 QwtFigure* gcf() const;
129
130 // Get the current axes (like matplotlib's gca)
131 QwtPlot* gca() const;
132
133 // Set the current axes (like matplotlib's sca)
134 void sca(QwtPlot* plot);
135
136 // ---- Figure operations ----
137
138 // Create a subplot in a grid layout (1-based index, like matplotlib)
139 QwtPlot* subplot(int rows, int cols, int index);
140
141 // Add axes at a normalized rectangle position
142 QwtPlot* addAxes(const QRectF& rect = QRectF(0.1, 0.1, 0.8, 0.8));
143
144 // Create a twin Y-axis (like matplotlib's twinx)
145 QwtPlot* twinx(QwtPlot* host = nullptr);
146
147 // Create a twin X-axis (like matplotlib's twiny)
148 QwtPlot* twiny(QwtPlot* host = nullptr);
149
150 // Apply tight layout to align all subplot axes
151 void tightLayout();
152
153 // ---- Plotting methods (operate on gca()) ----
154
155 // Plot y-only data (x = index)
156 QwtPlotCurve* plot(const QVector< double >& y, const QString& fmt = QString(), const QString& label = QString());
157
158 // Plot x-y data from separate vectors
159 QwtPlotCurve* plot(const QVector< double >& x,
160 const QVector< double >& y,
161 const QString& fmt = QString(),
162 const QString& label = QString());
163
164 // Plot from QPointF data
165 QwtPlotCurve* plot(const QVector< QPointF >& data, const QString& fmt = QString(), const QString& label = QString());
166
167 // Scatter plot (markers only, no lines)
168 QwtPlotCurve* scatter(const QVector< double >& x,
169 const QVector< double >& y,
170 double size = 20,
171 const QString& color = QString(),
172 const QString& label = QString());
173
174 // Bar chart from y-only values (x = index)
175 QwtPlotBarChart* bar(const QVector< double >& values, const QString& color = QString(), const QString& label = QString());
176
177 // Bar chart from x-y data with configurable width
179 const QVector< double >& values,
180 double width = 0.8,
181 const QString& color = QString(),
182 const QString& label = QString());
183
184 // Histogram from raw data with automatic binning
186 hist(const QVector< double >& data, int bins = 10, const QString& color = QString(), const QString& label = QString());
187
188 // Box plot from pre-computed box samples
189 QwtPlotBoxChart* boxplot(const QVector< QwtBoxSample >& data, const QString& label = QString());
190
191 // Fill the area between two curves
192 QwtPlotIntervalCurve* fillBetween(const QVector< double >& x,
193 const QVector< double >& y1,
194 const QVector< double >& y2,
195 const QString& color = QString(),
196 double alpha = 0.3);
197
198 // Error bars (symmetric y-error)
199 QwtPlotIntervalCurve* errorbar(const QVector< double >& x,
200 const QVector< double >& y,
201 const QVector< double >& yerr,
202 const QString& fmt = QString(),
203 const QString& label = QString());
204
205 // Display a 2D matrix as a color-mapped image
207 imshow(const QVector< QVector< double > >& data, const QString& cmap = "viridis", double vmin = 0.0, double vmax = 0.0);
208
209 // Draw contour lines from a 2D matrix
210 QwtPlotSpectrogram* contour(const QVector< QVector< double > >& data,
211 const QList< double >& levels = {},
212 const QString& cmap = "viridis");
213
214 // Quiver plot (vector field)
215 QwtPlotVectorField* quiver(const QVector< double >& x,
216 const QVector< double >& y,
217 const QVector< double >& u,
218 const QVector< double >& v,
219 const QString& color = QString());
220
221 // Candlestick (OHLC) chart
222 QwtPlotTradingCurve* candlestick(const QVector< QwtOHLCSample >& data, const QString& label = QString());
223
224 // ---- Auxiliary elements ----
225
226 // Add or remove a grid
227 QwtPlotGrid* grid(bool show = true, bool minor = false);
228
229 // Add a horizontal line at y
230 QwtPlotMarker* axhline(double y, const QString& fmt = QString());
231
232 // Add a vertical line at x
233 QwtPlotMarker* axvline(double x, const QString& fmt = QString());
234
235 // Add a horizontal colored span between y1 and y2
236 QwtPlotZoneItem* axhspan(double y1, double y2, const QString& color = QString(), double alpha = 0.3);
237
238 // Add a vertical colored span between x1 and x2
239 QwtPlotZoneItem* axvspan(double x1, double x2, const QString& color = QString(), double alpha = 0.3);
240
241 // Add an arrow annotation from xytext to xy
242 QwtPlotArrowMarker* annotate(const QString& text, const QPointF& xy, const QPointF& xytext);
243
244 // Add a legend (in-canvas legend item)
245 QwtPlotLegendItem* legend(const QString& loc = "best");
246
247 // ---- Axis configuration ----
248
249 // Set the plot title
250 void setTitle(const QString& title);
251
252 // Set the X-axis label
253 void setXLabel(const QString& label);
254
255 // Set the Y-axis label
256 void setYLabel(const QString& label);
257
258 // Set X-axis limits
259 void setXLim(double min, double max);
260
261 // Set Y-axis limits
262 void setYLim(double min, double max);
263
264 // Set X-axis scale type ("linear" or "log")
265 void setXScale(const QString& scale);
266
267 // Set Y-axis scale type ("linear" or "log")
268 void setYScale(const QString& scale);
269
270 // Set custom X-axis tick positions and optional labels
271 void setXTicks(const QVector< double >& ticks, const QStringList& labels = {});
272
273 // Set custom Y-axis tick positions and optional labels
274 void setYTicks(const QVector< double >& ticks, const QStringList& labels = {});
275
276 // Invert the X-axis
277 void invertXAxis();
278
279 // Invert the Y-axis
280 void invertYAxis();
281
282 // ---- Appearance ----
283
284 // Set figure background color
285 void setFaceColor(const QString& color);
286
287 // Set axes canvas background color
288 void setAxesColor(const QString& color);
289
290 // Add a colorbar for a spectrogram
291 void colorbar(QwtPlotSpectrogram* spectro = nullptr);
292
293 // ---- Output ----
294
295 // Save figure to file
296 bool savefig(const QString& filename, int dpi = -1);
297
298 // Show the figure or plot widget
299 void show();
300
301 // ---- Interaction ----
302
303 // Enable/disable canvas panning
304 void enablePan(bool enable = true);
305
306 // Enable/disable canvas zooming (rubber-band)
307 void enableZoom(bool enable = true);
308
309private:
310 // Apply a parsed format string to a curve
311 void applyFormat(QwtPlotCurve* curve, const QwtFormatString& f);
312
313 // Apply a parsed format string to a marker
314 void applyFormat(QwtPlotMarker* marker, const QwtFormatString& f);
315
316 // Parse a named color string to QColor
317 static QColor namedColor(const QString& name);
318
319 // Create a color map by name
320 static class QwtLinearColorMap* createColorMap(const QString& name);
321
322 QWT_DECLARE_PRIVATE(QwtPyPlot)
323};
324
325#endif // QWT_PYPLOT_H
Sample for box-and-whisker plot (boxplot) visualization
Definition qwt_samples.h:363
A figure container for organizing Qwt plots with flexible layout options
Definition qwt_figure.h:47
QwtLinearColorMap builds a color map from color stops.
Definition qwt_colormap.h:87
Open-High-Low-Close sample used in financial charts
Definition qwt_samples.h:210
A class for drawing arrow markers on plots
Definition qwt_plot_arrowmarker.h:59
QwtPlotBarChart displays a series of values as bars
Definition qwt_plot_barchart.h:59
Plot item for box-and-whisker (boxplot) visualization
Definition qwt_plot_boxchart.h:37
A plot item, that represents a series of points
Definition qwt_plot_curve.h:75
A class which draws a coordinate grid
Definition qwt_plot_grid.h:51
QwtPlotHistogram represents a series of samples, where an interval is associated with a value ( )
Definition qwt_plot_histogram.h:60
QwtPlotIntervalCurve represents a series of samples, where each value is associated with an interval ...
Definition qwt_plot_intervalcurve.h:46
A class which draws a legend inside the plot canvas
Definition qwt_plot_legenditem.h:59
A class for drawing markers
Definition qwt_plot_marker.h:63
A plot item, which displays a spectrogram
Definition qwt_plot_spectrogram.h:55
QwtPlotTradingCurve illustrates movements in the price of a financial instrument over time
Definition qwt_plot_tradingcurve.h:54
A plot item, that represents a vector field
Definition qwt_plot_vectorfield.h:47
A plot item, which displays a zone
Definition qwt_plot_zoneitem.h:49
A 2-D plotting widget
Definition qwt_plot.h:99
Matplotlib pyplot-like interface for Qwt plotting
Definition qwt_pyplot.h:113
Style
Symbol Style
Definition qwt_symbol.h:58
@ NoSymbol
No Style. The symbol cannot be drawn.
Definition qwt_symbol.h:60
Parsed representation of a matplotlib-style format string
Definition qwt_pyplot.h:57