JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtpboxplot.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3
4
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License (LGPL) as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License (LGPL) for more details.
15
16 You should have received a copy of the GNU Lesser General Public License (LGPL)
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef jkqtpgraphsboxplot_H
21#define jkqtpgraphsboxplot_H
22
23
24#include <QString>
25#include <QPainter>
26#include <QPair>
27#include "jkqtplotter/jkqtptools.h"
28#include "jkqtplotter/jkqtplotter_imexport.h"
29#include "jkqtplotter/jkqtpimagetools.h"
30#include "jkqtplotter/jkqtpgraphsbase.h"
31#include "jkqtplotter/graphs/jkqtpboxplotbase.h"
32#include "jkqtplotter/graphs/jkqtpboxplotstylingmixins.h"
33#include "jkqtplotter/jkqtpgraphsbasestylingmixins.h"
34
35
36
37
38
39/*! \brief This implements vertical <a href="http://en.wikipedia.org/wiki/Box_plot">boxplots</a>, optionally also a notched boxplot
40 \ingroup jkqtplotter_statgraphs
41
42 The x position is given in posColumn. All other data are given in the medianColumn, minColumn, maxColumn,
43 percentile25Column and percentile75Column.
44
45 \image html JKQTPBoxplotVerticalGraph.png
46
47
48 The different features of a boxplot are:
49
50 \image html plot_boxplotverticalelement.png
51
52
53 The example \ref JKQTPlotterBoxplotStyling discusses different options to style boxplots:
54
55 \image html test_styledboxplot.png
56
57 This class also implements hitTest() in a way that displays all data of the boxplot in the tooltips:
58
59 \image html tooltip_boxplot.png
60
61 \note There are additional classes to draw a single boxplot element: JKQTPBoxplotHorizontalElement and JKQTPBoxplotVerticalElement.
62 In these you can set the data values, as they are NOT drawn from a data column. This can be useful, if you e.g. want to
63 draw the statistical properties of a distribution.
64
65 \section BoxplotOutliers Outliers
66
67 If you also want to display outliers, as shown here with circles:
68
69 \image html boxplot_outliers.png
70
71 You need to add them as (x,y)-pairs to the datastore and add a separate JKQTPXYLineGraph that shows these. See \ref JKQTPlotterBoxplotsGraphs for details. Here is an example code-snippet:
72
73 \code
74 // 4. create a graph of vertical boxplots:
75 JKQTPBoxplotVerticalGraph* graph=new JKQTPBoxplotVerticalGraph(&plot);
76 graph->setPositionColumn(columnPOS);
77 graph->setMinColumn(columnMIN);
78 graph->setPercentile25Column(columnQ25);
79 graph->setMedianColumn(columnMEDIAN);
80 graph->setMeanColumn(columnMEAN);
81 graph->setPercentile75Column(columnQ75);
82 graph->setMaxColumn(columnMAX);
83 graph->setTitle("vertical Boxplots");
84
85 // 5. outliers need to be drawn separately
86 JKQTPXYLineGraph* graphOutliers=new JKQTPXYLineGraph(&plot);
87 graphOutliers->setXColumn(columnOUTLIERSX);
88 graphOutliers->setYColumn(columnOUTLIERSY);
89 graphOutliers->setTitle("outliers");
90 // make the color a darker shade of the color of graph
91 graphOutliers->setColor(graph->getColor().darker());
92 graphOutliers->setFillColor(QColor("white"));
93 // draw outliers as small circles, without lines
94 graphOutliers->setSymbolType(JKQTPCircle);
95 graphOutliers->setDrawLine(false);
96 graphOutliers->setSymbolSize(7);
97 \endcode
98
99 \see \ref JKQTPlotterBoxplotsGraphs, jkqtpstatVAddBoxplots(),\ref JKQTPlotterBasicJKQTPDatastoreStatisticsGroupedStat, \ref JKQTPlotterBasicJKQTPDatastoreStatistics, \ref JKQTPlotterBoxplotStyling
100
101 */
103 Q_OBJECT
104 public:
105
106
107 /** \brief class constructor */
109 /** \brief class constructor */
111
112 /** \brief plots the graph to the plotter object specified as parent */
113 virtual void draw(JKQTPEnhancedPainter& painter) override;
114 /** \copydoc JKQTPBoxplotGraphBase::drawKeyMarker() */
115 virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) override;
116
117 /** \copydoc JKQTPPlotElement::getXMinMax() */
118 virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override;
119 /** \copydoc JKQTPPlotElement::getYMinMax() */
120 virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override;
121
122 protected:
123
124};
125
126
127/*! \brief This implements horizontal <a href="http://en.wikipedia.org/wiki/Box_plot">boxplots</a>, optionally also a notched boxplot
128 \ingroup jkqtplotter_statgraphs
129
130 the x position is given in posColumn. All other data are given in the medianColumn, minColumn, maxColumn,
131 percentile25Column and percentile75Column.
132
133 \image html JKQTPBoxplotHorizontalGraph.png
134
135 \note See the documentation of JKQTPBoxplotVerticalGraph for details on the properties of this class!
136
137 \see JKQTPBoxplotVerticalGraph \ref JKQTPlotterBoxplotsGraphs, jkqtpstatHAddBoxplots(), \ref JKQTPlotterBasicJKQTPDatastoreStatisticsGroupedStat, \ref JKQTPlotterBasicJKQTPDatastoreStatistics, \ref JKQTPlotterBoxplotStyling
138
139 */
141 Q_OBJECT
142 public:
143 /** \brief class constructor */
146
147 /** \brief plots the graph to the plotter object specified as parent */
148 virtual void draw(JKQTPEnhancedPainter& painter) override;
149 /** \brief plots a key marker inside the specified rectangle \a rect */
150 virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) override;
151
152
153 /** \copydoc JKQTPPlotElement::getXMinMax() */
154 virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override;
155 /** \copydoc JKQTPPlotElement::getYMinMax() */
156 virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override;
157};
158
159
160
161
162
163
164
165
166/*! \brief This implements a single vertical <a href="http://en.wikipedia.org/wiki/Box_plot">(notched) boxplot</a> as a "geometric element",
167 where the data is directly given to the object and not stored in a column, as in JKQTPBoxplotVerticalGraph
168 \ingroup jkqtplotter_statgraphs
169 \ingroup jkqtplotter_statgraphs
170
171
172
173 the x position is given in posColumn. All other data are given in the median, min, max,
174 percentile25 and percentile75.
175
176 The different features of a boxplot are:
177
178 \image html plot_boxplotverticalelement.png
179
180
181 The example \ref JKQTPlotterBoxplotStyling discusses different options to style boxplots:
182
183 \image html test_styledboxplot.png
184
185 \see jkqtpstatVAddBoxplot(), \ref JKQTPlotterBasicJKQTPDatastoreStatistics, \ref JKQTPlotterBoxplotsGraphs, \ref JKQTPlotterBoxplotStyling, jkqtpstatAddVBoxplotAndOutliers()
186
187 */
189 Q_OBJECT
190 public:
191 /** \brief class constructor */
193 /** \brief class constructor */
195
196 /** \brief plots the graph to the plotter object specified as parent */
197 virtual void draw(JKQTPEnhancedPainter& painter) override;
198 /** \brief plots a key marker inside the specified rectangle \a rect */
199 virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) override;
200
201
202 /** \copydoc JKQTPPlotElement::getXMinMax() */
203 virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override;
204 /** \copydoc JKQTPPlotElement::getYMinMax() */
205 virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override;
206
207
208 protected:
209
210
211};
212
213
214/*! \brief This implements a horizontal <a href="http://en.wikipedia.org/wiki/Box_plot">(notched) boxplot</a> where the data is directly given to the
215 object and not stored in a column, as in JKQTPBoxplotVerticalGraph
216 \ingroup jkqtplotter_statgraphs
217 \ingroup jkqtplotter_statgraphs
218
219 the x position is given in pos. All other data are given in the median, min, max,
220 percentile25 and percentile75.
221
222 \image html plot_boxplothorizontalelement.png
223
224 \note See JKQTPBoxplotVerticalElement for a detailed documentation
225
226 \see JKQTPBoxplotVerticalElement, jkqtpstatHAddBoxplot(), \ref JKQTPlotterBasicJKQTPDatastoreStatistics, \ref JKQTPlotterBoxplotsGraphs, \ref JKQTPlotterBoxplotStyling, jkqtpstatAddHBoxplotAndOutliers()
227
228 */
230 Q_OBJECT
231 public:
232 /** \brief class constructor */
234 /** \brief class constructor */
236
237 /** \brief plots the graph to the plotter object specified as parent */
238 virtual void draw(JKQTPEnhancedPainter& painter) override;
239 /** \brief plots a key marker inside the specified rectangle \a rect */
240 virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, const QRectF& rect) override;
241
242
243 /** \copydoc JKQTPPlotElement::getXMinMax() */
244 virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override;
245 /** \copydoc JKQTPPlotElement::getYMinMax() */
246 virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override;
247};
248
249
250
251#endif // jkqtpgraphsboxplot_H
base class for 2D plotter classes (used by the plotter widget JKQTPlotter)
Definition jkqtpbaseplotter.h:394
Tbaseclass for a single (notched) boxplot as a "geometric element", where the data is directly given ...
Definition jkqtpboxplotbase.h:192
Base class for graphs representing a series of boxplot, elements.
Definition jkqtpboxplotbase.h:51
This implements a horizontal (notched) boxplot where the data is directly given to the object and not...
Definition jkqtpboxplot.h:229
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
virtual bool getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) override
get the maximum and minimum y-value of the graph
JKQTPBoxplotHorizontalElement(JKQTBasePlotter *parent=nullptr)
class constructor
virtual void drawKeyMarker(JKQTPEnhancedPainter &painter, const QRectF &rect) override
plots a key marker inside the specified rectangle rect
virtual bool getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) override
get the maximum and minimum x-value of the graph
JKQTPBoxplotHorizontalElement(JKQTPlotter *parent)
class constructor
This implements horizontal boxplots, optionally also a notched boxplot.
Definition jkqtpboxplot.h:140
virtual void drawKeyMarker(JKQTPEnhancedPainter &painter, const QRectF &rect) override
plots a key marker inside the specified rectangle rect
virtual bool getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) override
get the maximum and minimum y-value of the graph
JKQTPBoxplotHorizontalGraph(JKQTPlotter *parent)
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
JKQTPBoxplotHorizontalGraph(JKQTBasePlotter *parent=nullptr)
class constructor
virtual bool getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) override
get the maximum and minimum x-value of the graph
This implements a single vertical (notched) boxplot as a "geometric element", where the data is direc...
Definition jkqtpboxplot.h:188
JKQTPBoxplotVerticalElement(JKQTPlotter *parent)
class constructor
virtual void drawKeyMarker(JKQTPEnhancedPainter &painter, const QRectF &rect) override
plots a key marker inside the specified rectangle rect
virtual bool getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) override
get the maximum and minimum x-value of the graph
JKQTPBoxplotVerticalElement(JKQTBasePlotter *parent=nullptr)
class constructor
virtual bool getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) override
get the maximum and minimum y-value of the graph
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
This implements vertical boxplots, optionally also a notched boxplot.
Definition jkqtpboxplot.h:102
virtual void drawKeyMarker(JKQTPEnhancedPainter &painter, const QRectF &rect) override
plots a key marker inside the specified rectangle rect
JKQTPBoxplotVerticalGraph(JKQTPlotter *parent)
class constructor
virtual bool getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) override
get the maximum and minimum y-value of the graph
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
JKQTPBoxplotVerticalGraph(JKQTBasePlotter *parent=nullptr)
class constructor
virtual bool getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) override
get the maximum and minimum x-value of the graph
this class extends the QPainter
Definition jkqtpenhancedpainter.h:33
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
#define JKQTPLOTTER_LIB_EXPORT
Definition jkqtplotter_imexport.h:89