QT's rendering of statistical images, function images, etc. is not helped by the relevant components, but only by drawing pictures manually.
Qwtplot is a widget for drawing two-dimensional images, inherited from Qframe and qwtplotdict. But strictly speaking, it's just a view window, and the real drawing device is its central part Qwtplotcanvas class.
The drawing component can be displayed without restrictions on its artboard. Painting components can be curves (qwtplotcurve), Markers (Qwtplotmarker), meshes (Qwtplotgrid), or other components that inherit from Qwtplotitem.
Qwtplot has 4 axes (axes)
A qwtplot has four coordinates, each of which is attached to the x-axis or the y-axis. The scale of each axis can be configured individually via set (Qwtscalediv) or by an algorithm (Qwtscaleengine) based on the plotted entity.
variables |
function |
Yleft |
Y Axis left of the canvas. |
Yright |
Y axis right of the canvas. |
Xbottom |
X axis below the canvas. |
Xtop |
X axis above the canvas. |
Common function interfaces
Interface |
function |
Setaxistitle |
Set axis Title |
Enableaxis |
Mainly displays the xtop,yright axis |
Setaxismaxmajor |
Set the maximum number of intervals for an axis to enlarge a scale bar |
Setaxismaxminor |
Set the maximum number of intervals for an axis to scale down |
Setaxisscale |
Disables the Autoscale scale bar, specifying a modified scale bar for an axis |
Insertlegend |
Add a Legend (callout) |
Common components
Components |
function |
Qwtplotcurve |
Curve |
Qwtplotmarker |
Mark |
Qwtplotgrid |
Grid |
Qwtplothistogram |
Histogram |
Other |
Components inherited from Qwtplotitem |
Qwtplotitem plot |
can display the class, if you want to implement your own drawing graphics, to inherit this class implementation Rtti and Draw interface |
Qwtplotpanner |
Pan (pan with left mouse button) |
Qwtplotmagnifier |
Amplifier (zoom with mouse wheel) |
Qwtplotcanvas |
Canvas |
Qwtscalemap |
Scale diagram-can provide a logical area to the actual area of the coordinate transformation |
Qwtscalewidget |
Proportional window |
Qwtscalediv |
Scale layout |
Qwtlegent |
Marking |
Qwtplotlayout |
Layout Manager |
Qwtscaledraw |
Self-drawing axes |
Qwtplotcure Introduction
Common Interfaces |
function |
Setpen |
Set Brush |
SetData |
Set the data for a curve |
SetStyle |
Set the Curve form, point, line, dash, etc. |
Setcurveattribute |
Set curve properties, general settings fitted |
Attch |
Attach the curve to the Qwlplot |
Here is a small example, the results are as follows:
This example draws two sin curves and automatically refreshes the curve display, one curve is a flat curve, the other is a hard inflection point curve, and then press the key to make two curves to the right, note that while moving multiple curves in the case do not use the SetData function, the program will mistakenly exit, You should use the Setsamples function, see the code
#ifndef Mainwindow_h#define Mainwindow_h#include <QMainWindow>#include <QDebug>#include <Qt/qmath.h>#include <QVector>#include <qwt_plot.h>#include <qwt_plot_curve.h>#include <qwt_plot_magnifier.h>#include <qwt_plot_panner.h> #include <qwt_legend.h> #include <qwt_ Point_data.h>namespace Ui {class MainWindow;} class MainWindow: public qmainwindow{q_objectpublic: explicit MainWindow (qwidget *parent = 0) ; ~mainwindow (); private Slots: void on_pushbutton_clicked (); private:ui::mainwindow *ui; Qwtplotcurve curve; Qwtplotcurve Curve_r; //hard vertex curve canvas qvector<double> xs; Qvector<double> ys;}; #endif //mainwindow_h
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
#include "Mainwindow.h"#include "Ui_mainwindow.h"#include <QHBoxLayout>#include <QtGui/QApplication>#include <Qt/qmath.h>#include <QVector>#include <qwt_plot.h>#include <qwt_plot_curve.h>#include <qwt_plot_magnifier.h>#include <qwt_plot_panner.h>#include <qwt_legend.h>#include <qwt_point_data.h>mainwindow::mainwindow (qwidget *parent): Qmainwindow (parent), UI (New Ui::mainwindow) {UI->SETUPUI (this); Ui->plot->resize (640,400); Ui->plot->setautoreplot (true);Set the name of the axis ui->plot->setaxistitle (Qwtplot::xbottom,"X->"); Ui->plot->setaxistitle (Qwtplot::yleft,"Y->");Set the range of axes Ui->plot->setaxisscale (Qwtplot::yleft,-1.0,1.0);Set the right callout ui->plot->insertlegend (New Qwtlegend (), qwtplot::rightlegend);Use the wheel to enlarge/shrink (voidNew Qwtplotmagnifier (Ui->plot->canvas ());Use the left mouse button to pan (voidNew Qwtplotpanner (Ui->plot->canvas ());Calculate curve Datafor (Double x =0; X <2.0 * M_PI; x+= (M_PI/10.0) {xs.append (x); Ys.append (Qsin (x));}Smooth curve Curve.attach (ui->plot);//attach the curve to plot curve.setsamples (Xs,ys); Curve.setstyle (qwtplotcurve::lines); //set the curve is the point or line, the default is the line, so this line can not add Curve.setcurveattribute (qwtplotcurve::fitted, true); //make the curve more smooth, do not add this curve will be very tough, there is a folding Curve.setpen (Qpen (Qt::blue)); //set Brush Curve_r.attach (Ui->plot); Curve_r.setsamples (Xs,ys) Curve_r.setpen (QPen (Qt: : green));} Mainwindow::~mainwindow () {Delete UI;} void mainwindow::on_pushbutton_clicked () {for (int i=ys.count ()-1;i>=1;i--) {ys[i]=ys.at ( I-1); } ys[0]=0.5; Curve.setsamples (Xs,ys); Curve_r.setSamples (XS, ys);}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
Scatter plot:
Header File Class ccruveplot:publicqwtplot{PublicCcruveplot (); ~ccruveplot (void);PublicvoidDrawplotcruve ();Private:qwtplotcurve * curve; qvector<Double> XData; qvector<Double> Ydata;};Implementation file:#include "CruvePlot.h"Constint linenum=7;Constint pointnum=7; Ccruveplot::ccruveplot () {}ccruveplot::~ccruveplot (void) {}void Ccruveplot::d rawplotcruve () {Qmessagebox::information (This, "running! "," Running matlab Function ... "); Settitle ("A simple Qwtplot demonstration");Set the title Insertlegend (New Qwtlegend (), qwtplot::rightlegend);Set the line setaxistitle of the markings (Xbottom,"X--"); Setaxisscale (Xbottom,0.0,10.0); Setaxistitle (Yleft,"Y--and"); Setaxisscale (Yleft,0,10.0); Qwtplotcurve *curve =New Qwtplotcurve ("Linefirst");Instantiate a curve Curve->attach (this);Double *x=NewDouble[pointnum];Double *y=NewDouble[pointnum];Forint i=0;i<pointnum;i++) {x[i]=i; y[i]=i+3;} Curve->setsamples (X,y,pointnum); //The Data Curve->setpen (Qpen (qt::red)) of the plot curve; Qwtplotcurve *curve2 = new qwtplotcurve ( "LineSecond"); //Instantiate another line Curve2->attach (this); double *x2=new double[PointNum] ; double *y2=new double[PointNum] ; for (int i=0;i<PointNum;i++) { X2[i]=i*3; Y2[i]=i+3;} curve2->setsamples (X2,y2,PointNum) ; Curve2->setpen (Qpen (Qt::blue)); return;}
http://blog.csdn.net/u013007900/article/details/50055353
The Qwtplot of QT Learning (mathematical mapping)