mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 17:41:39 +08:00
added example project for error indicator styles
This commit is contained in:
parent
97f8b48642
commit
cdf76539b3
@ -22,6 +22,7 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_logaxes) | [logarithmic axes](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_logaxes) | `JKQTPxyLineGraph` and `JKQTPgeoText`<br/>C++ vector of data<br/>logarithmic axes<br/>plot line styles<br/>internal LaTeX parser<br/>add commenting text to a graph |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_small.png)<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_dates_small.png)<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_timeaxis_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_dateaxes) | [date/time axes](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_dateaxes) | `JKQTPxyLineGraph` and `JKQTPfilledVerticalRangeGraph`<br/>C++ vector of data<br/>date/time axes<br/>plot min/max range graph<br/>internal LaTeX parser<br/>data from CSV files |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_symbols_and_errors_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_errors) | [Simple Line/Symbol Graph With Errorbars](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_errors) | `JKQTPxyLineErrorGraph`<br/>C-style arrays of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_errorbarstyles) | [Different Types of Errorindicators](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_errorbarstyles) | `JKQTPxyLineErrorGraph`<br/>different styles of error indicators for x- and y-errors<br>C++-style QVector for data<br/>styling error indicators<br/>moving key and formatting plotter grid |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_barchart_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_barchart) | [Simple Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_barchart) | `JKQTPbarVerticalGraph`<br/>C-style arrays of data |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/JKQTPbarVerticalGraphStacked_small.png)<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/JKQTPbarHorizontalGraphStacked_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_stackedbars) | [Stacked Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_stackedbars) | `JKQTPbarVerticalStackableGraph`, `JKQTPbarHorizontalStackableGraph`<br/>C++-style vectors of data |
|
||||
|
||||
|
@ -3158,13 +3158,13 @@ void JKQtBasePlotter::resetMasterSynchronization() {
|
||||
|
||||
size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title, JKQTPgraphPlotstyle graphStyle) {
|
||||
if (graphStyle==JKQTPimpulsesHorizontal) {
|
||||
JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this);
|
||||
JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this);
|
||||
gr->set_title(title);
|
||||
gr->set_xColumn(xColumn);
|
||||
gr->set_yColumn(yColumn);
|
||||
return addGraph(gr);
|
||||
} else if (graphStyle==JKQTPimpulsesVertical) {
|
||||
JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this);
|
||||
JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this);
|
||||
gr->set_title(title);
|
||||
gr->set_xColumn(xColumn);
|
||||
gr->set_yColumn(yColumn);
|
||||
@ -3207,7 +3207,7 @@ size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title,
|
||||
|
||||
size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title, JKQTPgraphPlotstyle graphStyle, QColor color, JKQTPgraphSymbols symbol, Qt::PenStyle penstyle, double width) {
|
||||
if (graphStyle==JKQTPimpulsesHorizontal) {
|
||||
JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this);
|
||||
JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this);
|
||||
gr->set_title(title);
|
||||
gr->set_xColumn(xColumn);
|
||||
gr->set_yColumn(yColumn);
|
||||
@ -3215,7 +3215,7 @@ size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title,
|
||||
gr->set_lineWidth(width);
|
||||
return addGraph(gr);
|
||||
} else if (graphStyle==JKQTPimpulsesVertical) {
|
||||
JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this);
|
||||
JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this);
|
||||
gr->set_title(title);
|
||||
gr->set_xColumn(xColumn);
|
||||
gr->set_yColumn(yColumn);
|
||||
|
@ -526,7 +526,7 @@ void JKQTPxyLineErrorGraph::drawErrorsBefore(JKQTPEnhancedPainter &painter)
|
||||
|
||||
|
||||
|
||||
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent):
|
||||
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent):
|
||||
JKQTPxyGraph(parent)
|
||||
{
|
||||
baseline=0;
|
||||
@ -540,7 +540,7 @@ JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* pare
|
||||
}
|
||||
}
|
||||
|
||||
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent):
|
||||
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtPlotter* parent):
|
||||
JKQTPxyGraph(parent)
|
||||
{
|
||||
baseline=0;
|
||||
@ -553,9 +553,9 @@ JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent):
|
||||
color=parent->getPlotStyle(parentPlotStyle).color();
|
||||
}
|
||||
}
|
||||
void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
|
||||
void JKQTPimpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
|
||||
#ifdef JKQTBP_AUTOTIMER
|
||||
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesHorizontalGraph::draw");
|
||||
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesVerticalGraph::draw");
|
||||
#endif
|
||||
if (parent==nullptr) return;
|
||||
JKQTPdatastore* datastore=parent->getDatastore();
|
||||
@ -627,7 +627,7 @@ void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
|
||||
drawErrorsAfter(painter);
|
||||
}
|
||||
|
||||
void JKQTPimpulsesHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
|
||||
void JKQTPimpulsesVerticalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
|
||||
|
||||
|
||||
painter.save();
|
||||
@ -642,7 +642,7 @@ void JKQTPimpulsesHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter,
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
QColor JKQTPimpulsesHorizontalGraph::getKeyLabelColor() {
|
||||
QColor JKQTPimpulsesVerticalGraph::getKeyLabelColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@ -656,20 +656,20 @@ QColor JKQTPimpulsesHorizontalGraph::getKeyLabelColor() {
|
||||
|
||||
|
||||
|
||||
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent):
|
||||
JKQTPimpulsesHorizontalGraph(parent)
|
||||
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent):
|
||||
JKQTPimpulsesVerticalGraph(parent)
|
||||
{
|
||||
}
|
||||
|
||||
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtPlotter *parent):
|
||||
JKQTPimpulsesHorizontalGraph(parent)
|
||||
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtPlotter *parent):
|
||||
JKQTPimpulsesVerticalGraph(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void JKQTPimpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
|
||||
void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
|
||||
#ifdef JKQTBP_AUTOTIMER
|
||||
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesVerticalGraph::draw");
|
||||
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesHorizontalGraph::draw");
|
||||
#endif
|
||||
if (parent==nullptr) return;
|
||||
JKQTPdatastore* datastore=parent->getDatastore();
|
||||
@ -1805,7 +1805,7 @@ QBrush JKQTPxyLineGraph::getBrush(JKQTPEnhancedPainter& /*painter*/) const {
|
||||
}
|
||||
|
||||
|
||||
QPen JKQTPimpulsesHorizontalGraph::getPen(JKQTPEnhancedPainter& painter) const {
|
||||
QPen JKQTPimpulsesVerticalGraph::getPen(JKQTPEnhancedPainter& painter) const {
|
||||
QPen p;
|
||||
p.setColor(color);
|
||||
p.setWidthF(qMax(JKQTPLOTTER_ABS_MIN_LINEWIDTH,parent->pt2px(painter, parent->get_lineWidthMultiplier()*lineWidth)));
|
||||
@ -1870,7 +1870,7 @@ QPen JKQTPhorizontalRange::getLinePen(JKQTPEnhancedPainter& painter) const {
|
||||
|
||||
bool JKQTPimpulsesHorizontalErrorGraph::usesColumn(int c)
|
||||
{
|
||||
return JKQTPimpulsesHorizontalGraph::usesColumn(c)|| JKQTPxGraphErrors::errorUsesColumn(c);
|
||||
return JKQTPimpulsesVerticalGraph::usesColumn(c)|| JKQTPxGraphErrors::errorUsesColumn(c);
|
||||
}
|
||||
|
||||
void JKQTPimpulsesHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter)
|
||||
@ -1880,20 +1880,20 @@ void JKQTPimpulsesHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &pa
|
||||
}
|
||||
|
||||
JKQTPimpulsesVerticalErrorGraph::JKQTPimpulsesVerticalErrorGraph(JKQtBasePlotter *parent):
|
||||
JKQTPimpulsesVerticalGraph(parent), JKQTPyGraphErrors()
|
||||
JKQTPimpulsesHorizontalGraph(parent), JKQTPyGraphErrors()
|
||||
{
|
||||
setErrorColorFromGraphColor(color);
|
||||
}
|
||||
|
||||
JKQTPimpulsesVerticalErrorGraph::JKQTPimpulsesVerticalErrorGraph(JKQtPlotter *parent):
|
||||
JKQTPimpulsesVerticalGraph(parent), JKQTPyGraphErrors()
|
||||
JKQTPimpulsesHorizontalGraph(parent), JKQTPyGraphErrors()
|
||||
{
|
||||
setErrorColorFromGraphColor(color);
|
||||
}
|
||||
|
||||
bool JKQTPimpulsesVerticalErrorGraph::usesColumn(int c)
|
||||
{
|
||||
return JKQTPimpulsesVerticalGraph::usesColumn(c)|| JKQTPyGraphErrors::errorUsesColumn(c);
|
||||
return JKQTPimpulsesHorizontalGraph::usesColumn(c)|| JKQTPyGraphErrors::errorUsesColumn(c);
|
||||
}
|
||||
|
||||
void JKQTPimpulsesVerticalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter)
|
||||
|
@ -360,13 +360,13 @@ class LIB_EXPORT JKQTPxyParametrizedErrorScatterGraph: public JKQTPxyParametrize
|
||||
|
||||
\image html plot_impulsesxplots.png
|
||||
*/
|
||||
class LIB_EXPORT JKQTPimpulsesHorizontalGraph: public JKQTPxyGraph {
|
||||
class LIB_EXPORT JKQTPimpulsesVerticalGraph: public JKQTPxyGraph {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/** \brief class constructor */
|
||||
JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent=nullptr);
|
||||
JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent=nullptr);
|
||||
/** \brief class constructor */
|
||||
JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent);
|
||||
JKQTPimpulsesVerticalGraph(JKQtPlotter* parent);
|
||||
|
||||
/** \brief plots the graph to the plotter object specified as parent */
|
||||
virtual void draw(JKQTPEnhancedPainter& painter);
|
||||
@ -401,17 +401,17 @@ class LIB_EXPORT JKQTPimpulsesHorizontalGraph: public JKQTPxyGraph {
|
||||
|
||||
\image html plot_impulsesxerrorsplots.png
|
||||
*/
|
||||
class LIB_EXPORT JKQTPimpulsesHorizontalErrorGraph: public JKQTPimpulsesHorizontalGraph, public JKQTPxGraphErrors {
|
||||
class LIB_EXPORT JKQTPimpulsesHorizontalErrorGraph: public JKQTPimpulsesVerticalGraph, public JKQTPxGraphErrors {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/** \brief class constructor */
|
||||
inline JKQTPimpulsesHorizontalErrorGraph(JKQtBasePlotter* parent=nullptr):
|
||||
JKQTPimpulsesHorizontalGraph(parent), JKQTPxGraphErrors()
|
||||
JKQTPimpulsesVerticalGraph(parent), JKQTPxGraphErrors()
|
||||
{
|
||||
setErrorColorFromGraphColor(color);
|
||||
}
|
||||
inline JKQTPimpulsesHorizontalErrorGraph(JKQtPlotter* parent):
|
||||
JKQTPimpulsesHorizontalGraph(parent), JKQTPxGraphErrors()
|
||||
JKQTPimpulsesVerticalGraph(parent), JKQTPxGraphErrors()
|
||||
{
|
||||
setErrorColorFromGraphColor(color);
|
||||
}
|
||||
@ -432,13 +432,13 @@ class LIB_EXPORT JKQTPimpulsesHorizontalErrorGraph: public JKQTPimpulsesHorizont
|
||||
|
||||
\image html plot_impulsesyplots.png
|
||||
*/
|
||||
class LIB_EXPORT JKQTPimpulsesVerticalGraph: public JKQTPimpulsesHorizontalGraph {
|
||||
class LIB_EXPORT JKQTPimpulsesHorizontalGraph: public JKQTPimpulsesVerticalGraph {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/** \brief class constructor */
|
||||
JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent=nullptr);
|
||||
JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent=nullptr);
|
||||
/** \brief class constructor */
|
||||
JKQTPimpulsesVerticalGraph(JKQtPlotter* parent);
|
||||
JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent);
|
||||
|
||||
/** \brief plots the graph to the plotter object specified as parent */
|
||||
virtual void draw(JKQTPEnhancedPainter& painter);
|
||||
@ -451,7 +451,7 @@ class LIB_EXPORT JKQTPimpulsesVerticalGraph: public JKQTPimpulsesHorizontalGraph
|
||||
|
||||
\image html plot_impulsesyerrorsplots.png
|
||||
*/
|
||||
class LIB_EXPORT JKQTPimpulsesVerticalErrorGraph: public JKQTPimpulsesVerticalGraph, public JKQTPyGraphErrors {
|
||||
class LIB_EXPORT JKQTPimpulsesVerticalErrorGraph: public JKQTPimpulsesHorizontalGraph, public JKQTPyGraphErrors {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/** \brief class constructor */
|
||||
|
BIN
screenshots/jkqtplotter_simpletest_errorbarstyles.png
Normal file
BIN
screenshots/jkqtplotter_simpletest_errorbarstyles.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 89 KiB |
BIN
screenshots/jkqtplotter_simpletest_errorbarstyles_barcharts.png
Normal file
BIN
screenshots/jkqtplotter_simpletest_errorbarstyles_barcharts.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
BIN
screenshots/jkqtplotter_simpletest_errorbarstyles_impulses.png
Normal file
BIN
screenshots/jkqtplotter_simpletest_errorbarstyles_impulses.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
BIN
screenshots/jkqtplotter_simpletest_errorbarstyles_small.png
Normal file
BIN
screenshots/jkqtplotter_simpletest_errorbarstyles_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
120
test/jkqtplotter_simpletest_errorbarstyles/README.md
Normal file
120
test/jkqtplotter_simpletest_errorbarstyles/README.md
Normal file
@ -0,0 +1,120 @@
|
||||
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)
|
||||
|
||||
# JKQtPlotter
|
||||
|
||||
## Different Types of Errorindicators
|
||||
This project (see `./test/jkqtplotter_simpletest_errorbarstyles/`) simply creates a JKQtPlotter widget (as a new window) and adds several curves show-casing different styles of error indicators. Data is initialized from two QVector<double> objects.
|
||||
|
||||
The source code of the main application can be found in [`jkqtplotter_simpletest_errorbarstyles.cpp`](https://github.com/jkriege2/JKQtPlotter/blob/master/test/jkqtplotter_simpletest_errorbarstyles/jkqtplotter_simpletest_errorbarstyles.cpp).
|
||||
|
||||
First some data is added to the internal datastore (mostly, like explained in several other examples, like e.g. [Line Graph with Different Symbols and Line Styles](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_styles)). The (in a loop) several graphs are added, each with a distinct style for its error indicators:
|
||||
|
||||
```c++
|
||||
// 3. now we make several plots with different error styles
|
||||
// for that we iterate over every style from the vector errorStyles
|
||||
// the array showXandYError indicates whether we want x- and y-error
|
||||
// for a style for all stywhere this is false, only y-error-indicators
|
||||
// are shown
|
||||
QVector<JKQTPerrorPlotstyle> errorStyles {JKQTPnoError, JKQTPerrorBars, JKQTPerrorSimpleBars, JKQTPerrorLines, JKQTPerrorPolygons, JKQTPerrorBoxes, JKQTPerrorEllipses, JKQTPerrorBarsPolygons, JKQTPerrorBarsLines, JKQTPerrorSimpleBarsLines, JKQTPerrorSimpleBarsPolygons };
|
||||
QVector<bool> showXandYError { false , true , true , false , false , true , true , false , false , false , false };
|
||||
|
||||
for (int errorID=0; errorID<errorStyles.size(); errorID++) {
|
||||
// generate some plot data
|
||||
QVector<double> Y;
|
||||
for (auto& xx: X) {
|
||||
Y<<xx*0.5+static_cast<double>(errorID)*2.5;
|
||||
}
|
||||
|
||||
// create a graph object
|
||||
JKQTPxyLineErrorGraph* graph=new JKQTPxyLineErrorGraph(&plot);
|
||||
|
||||
// copy data into datastore and immediately set the yColumn
|
||||
graph->set_xColumn(columnX);
|
||||
graph->set_yColumn(ds->addCopiedColumn(Y, "y"+QString::number(errorID)));
|
||||
graph->set_xErrorColumn(columnXError);
|
||||
graph->set_yErrorColumn(columnYError);
|
||||
|
||||
// set error style, for the y-axis
|
||||
graph->set_yErrorStyle(errorStyles[errorID]);
|
||||
// no error indicators for the x-values
|
||||
graph->set_xErrorStyle(JKQTPnoError);
|
||||
// ... unless: for some error styles we want error in both directions
|
||||
if (showXandYError[errorID]) {
|
||||
graph->set_xErrorStyle(errorStyles[errorID]);
|
||||
graph->set_drawLine(false);
|
||||
}
|
||||
// make error indicator 30% transparent
|
||||
QColor c=graph->get_errorFillColor();
|
||||
c.setAlphaF(0.3);
|
||||
graph->set_errorFillColor(c);
|
||||
// set error indicator line width
|
||||
graph->set_errorWidth(1);
|
||||
// set length of small bars at the end of error bars
|
||||
graph->set_errorbarSize(15);
|
||||
|
||||
|
||||
// set symbol (cross/X) + pen style (and color)dashed)
|
||||
graph->set_symbol(JKQTPcross);
|
||||
graph->set_style(Qt::DashLine);
|
||||
// set symbol size
|
||||
graph->set_symbolSize(5);
|
||||
// set width of symbol lines
|
||||
graph->set_symbolWidth(1);
|
||||
// set width of graph line
|
||||
graph->set_lineWidth(1);
|
||||
|
||||
// graph title is made from symbol+errorStylestyle, we use the LaTeX instruction \verb around the
|
||||
// result of JKQTPerrorPlotstyle2String(), because it contains underscores that would otherwise
|
||||
// lead to lower-case letter, which we don't want
|
||||
graph->set_title("\\verb{"+JKQTPerrorPlotstyle2String(errorStyles[errorID])+"}");
|
||||
|
||||
// add the graph to the plot, so it is actually displayed
|
||||
plot.addGraph(graph);
|
||||
}
|
||||
```
|
||||
|
||||
The error styles are set in these lines:
|
||||
```c++
|
||||
// set error style, for the y-axis
|
||||
graph->set_yErrorStyle(errorStyles[errorID]);
|
||||
// no error indicators for the x-values
|
||||
graph->set_xErrorStyle(errorStyles[errorID]);
|
||||
```
|
||||
|
||||
There are several variables that can be used to further style the error indicator, like:
|
||||
```c++
|
||||
// make error indicator 30% transparent
|
||||
QColor c=graph->get_errorFillColor();
|
||||
c.setAlphaF(0.3);
|
||||
graph->set_errorFillColor(c);
|
||||
// set error indicator line width
|
||||
graph->set_errorWidth(1);
|
||||
// set length of small bars at the end of error bars
|
||||
graph->set_errorbarSize(15);
|
||||
```
|
||||
|
||||
There are more properties that you can find in the documentation of the mix-in classes `JKQTPxyGraphErrors`, `JKQTPxGraphErrors`, `JKQTPyGraphErrors`, `JKQTPgraphErrors`.
|
||||
|
||||
In addition the plot key is moved outside the pot and the grid in the plot is switched off:
|
||||
```c++
|
||||
// 6. change locaion of key (outside top-right)
|
||||
plot.get_plotter()->set_keyPosition(JKQTPkeyOutsideRightTop);
|
||||
// ... and switch off the grid
|
||||
plot.getXAxis()->set_drawGrid(false);
|
||||
plot.getXAxis()->set_drawMinorGrid(false);
|
||||
plot.getYAxis()->set_drawGrid(false);
|
||||
plot.getYAxis()->set_drawMinorGrid(false);
|
||||
```
|
||||
|
||||
The result looks like this:
|
||||
|
||||
![jkqtplotter_simpletest_errorbarstyles](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles.png)
|
||||
|
||||
Error bars are implemented in the mixin-classes `JKQTPxyGraphErrors`, `JKQTPxGraphErrors` and `JKQTPyGraphErrors` that are all derived from `JKQTPgraphErrors`. With these it is simple to add error indicators to several different plot styles. Usually you can recognize these by looking at the class name, e.g. `JKQTPxyLineGraph` is a simple line+symbol graph, and `JKQTPxyLineErrorGraph` is the same with error indictaors (see above). There are also several other plots with error indicators:
|
||||
- `JKQTPbarVerticalErrorGraph` for barcharts with errors:<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles_barcharts.png)
|
||||
- `JKQTPimpulsesVerticalGraph` for impulse/candle-stick charts with errors:<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles_impulses.png)
|
||||
- `JKQTPfilledCurveXErrorGraph` for filled curves with errors:<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles_filledcurves.png)
|
||||
.
|
||||
|
||||
|
||||
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)
|
@ -0,0 +1,109 @@
|
||||
#include <QApplication>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplottertools/jkqtptools.h"
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
||||
JKQtPlotter plot;
|
||||
JKQTPdatastore* ds=plot.getDatastore();
|
||||
|
||||
// 2. now we create data a vector of x-values for a simple plot
|
||||
// and generate some values for varying errors
|
||||
// y-data for the pot will be generated later to position the
|
||||
// plot at different locations.
|
||||
QVector<double> X, Yerror, Xerror;
|
||||
const int Ndata=7; // number of plot points in each curve
|
||||
for (int i=0; i<Ndata; i++) {
|
||||
const double x=10.0+double(i)*2.0;
|
||||
X<<x;
|
||||
Yerror<<0.35+0.3*sin(x);
|
||||
Xerror<<0.35+0.3*sin(x);
|
||||
}
|
||||
// and copy it to the datastore
|
||||
size_t columnX=ds->addCopiedColumn(X, "x");
|
||||
size_t columnXError=ds->addCopiedColumn(Xerror, "xerror");
|
||||
size_t columnYError=ds->addCopiedColumn(Yerror, "yerror");
|
||||
|
||||
|
||||
// 3. now we make several plots with different error styles
|
||||
// for that we iterate over every style from the vector errorStyles
|
||||
// the array showXandYError indicates whether we want x- and y-error
|
||||
// for a style for all stywhere this is false, only y-error-indicators
|
||||
// are shown
|
||||
QVector<JKQTPerrorPlotstyle> errorStyles {JKQTPnoError, JKQTPerrorBars, JKQTPerrorSimpleBars, JKQTPerrorLines, JKQTPerrorPolygons, JKQTPerrorBoxes, JKQTPerrorEllipses, JKQTPerrorBarsPolygons, JKQTPerrorBarsLines, JKQTPerrorSimpleBarsLines, JKQTPerrorSimpleBarsPolygons };
|
||||
QVector<bool> showXandYError { false , true , true , false , false , true , true , false , false , false , false };
|
||||
|
||||
for (int errorID=0; errorID<errorStyles.size(); errorID++) {
|
||||
// generate some plot data
|
||||
QVector<double> Y;
|
||||
for (auto& xx: X) {
|
||||
Y<<xx*0.5+static_cast<double>(errorID)*2.5;
|
||||
}
|
||||
|
||||
JKQTPxyLineErrorGraph* graph=new JKQTPxyLineErrorGraph(&plot);
|
||||
|
||||
// copy data into datastore and immediately set the yColumn
|
||||
graph->set_xColumn(columnX);
|
||||
graph->set_yColumn(ds->addCopiedColumn(Y, "y"+QString::number(errorID)));
|
||||
graph->set_xErrorColumn(columnXError);
|
||||
graph->set_yErrorColumn(columnYError);
|
||||
|
||||
// set error style, for the y-axis
|
||||
graph->set_yErrorStyle(errorStyles[errorID]);
|
||||
// no error indicators for the x-values
|
||||
graph->set_xErrorStyle(JKQTPnoError);
|
||||
// ... unless: for some error styles we want error in both directions
|
||||
if (showXandYError[errorID]) {
|
||||
graph->set_xErrorStyle(errorStyles[errorID]);
|
||||
graph->set_drawLine(false);
|
||||
}
|
||||
// make error indicator 30% transparent
|
||||
QColor c=graph->get_errorFillColor();
|
||||
c.setAlphaF(0.3);
|
||||
graph->set_errorFillColor(c);
|
||||
// set error indicator line width
|
||||
graph->set_errorWidth(1);
|
||||
// set length of small bars at the end of error bars
|
||||
graph->set_errorbarSize(15);
|
||||
|
||||
|
||||
// set symbol (cross/X) + pen style (and color)dashed)
|
||||
graph->set_symbol(JKQTPcross);
|
||||
graph->set_style(Qt::DashLine);
|
||||
// set symbol size
|
||||
graph->set_symbolSize(5);
|
||||
// set width of symbol lines
|
||||
graph->set_symbolWidth(1);
|
||||
// set width of graph line
|
||||
graph->set_lineWidth(1);
|
||||
|
||||
// graph title is made from symbol+errorStylestyle, we use the LaTeX instruction \verb around the
|
||||
// result of JKQTPerrorPlotstyle2String(), because it contains underscores that would otherwise
|
||||
// lead to lower-case letter, which we don't want
|
||||
graph->set_title("\\verb{"+JKQTPerrorPlotstyle2String(errorStyles[errorID])+"}");
|
||||
|
||||
// add the graph to the plot, so it is actually displayed
|
||||
plot.addGraph(graph);
|
||||
}
|
||||
|
||||
// 4. autoscale the plot so the graph is contained
|
||||
plot.zoomToFit();
|
||||
|
||||
// 6. change locaion of key (outside top-right)
|
||||
plot.get_plotter()->set_keyPosition(JKQTPkeyOutsideRightTop);
|
||||
// ... and switch off the grid
|
||||
plot.getXAxis()->set_drawGrid(false);
|
||||
plot.getXAxis()->set_drawMinorGrid(false);
|
||||
plot.getYAxis()->set_drawGrid(false);
|
||||
plot.getYAxis()->set_drawMinorGrid(false);
|
||||
|
||||
// 7. show plotter and make it a decent size
|
||||
plot.show();
|
||||
plot.resize(800,600);
|
||||
|
||||
return app.exec();
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
# source code for this simple demo
|
||||
SOURCES = jkqtplotter_simpletest_errorbarstyles.cpp
|
||||
|
||||
# configure Qt
|
||||
CONFIG += qt
|
||||
QT += core gui svg
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
|
||||
|
||||
# output executable name
|
||||
TARGET = jkqtplotter_simpletest_errorbarstyles
|
||||
|
||||
# include JKQtPlotter source code
|
||||
include(../../lib/jkqtplotter.pri)
|
||||
# here you can activate some debug options
|
||||
#DEFINES += SHOW_JKQTPLOTTER_DEBUG
|
||||
#DEFINES += JKQTBP_AUTOTIMER
|
Loading…
Reference in New Issue
Block a user