BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
HistogramPlot.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/PlotComparison/HistogramPlot.cpp
6 //! @brief Implements class HistogramPlot
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 
19  : QWidget(parent)
20  , m_customPlot(new QCustomPlot)
21 
22 {
23  auto* vlayout = new QVBoxLayout(this);
24  vlayout->setMargin(0);
25  vlayout->setSpacing(0);
26  vlayout->setContentsMargins(0, 0, 0, 0);
27  vlayout->addWidget(m_customPlot);
28  m_customPlot->setAttribute(Qt::WA_NoMousePropagation, false);
29  setLayout(vlayout);
30  setStyleSheet("background-color:white;");
31 
32  initGraph();
33 
34  m_customPlot->xAxis->setTickLabelFont(
35  QFont(QFont().family(), GUI::Constants::plot_tick_label_size()));
36  m_customPlot->yAxis->setTickLabelFont(
37  QFont(QFont().family(), GUI::Constants::plot_tick_label_size()));
38 
39  m_customPlot->yAxis->setScaleType(QCPAxis::stLogarithmic);
40  m_customPlot->yAxis->setNumberFormat("eb");
41  m_customPlot->yAxis->setNumberPrecision(0);
42 
43  m_customPlot->xAxis->setLabel("iteration");
44  m_customPlot->yAxis->setLabel("chi2");
45 
46  m_customPlot->xAxis->setLabelFont(
47  QFont(QFont().family(), GUI::Constants::plot_axes_label_size()));
48  m_customPlot->yAxis->setLabelFont(
49  QFont(QFont().family(), GUI::Constants::plot_axes_label_size()));
50 }
51 
52 void HistogramPlot::addData(double x, double y)
53 {
54  m_customPlot->graph()->addData(x, y);
55  m_customPlot->graph()->rescaleAxes();
56  m_customPlot->replot();
57 }
58 
59 void HistogramPlot::addData(const QVector<double>& x, const QVector<double>& y)
60 {
61  m_customPlot->graph()->addData(x, y);
62  m_customPlot->graph()->rescaleAxes();
63  m_customPlot->replot();
64 }
65 
66 void HistogramPlot::setData(const QVector<double>& x, const QVector<double>& y)
67 {
68  m_customPlot->graph()->setData(x, y);
69  m_customPlot->graph()->rescaleAxes();
70  m_customPlot->replot();
71 }
72 
74 {
75  m_customPlot->removeGraph(m_customPlot->graph());
76  initGraph();
77  m_customPlot->replot();
78 }
79 
81 {
82  m_customPlot->addGraph();
83 
84  QPen pen(QColor(0, 0, 255, 200));
85  m_customPlot->graph()->setLineStyle(QCPGraph::lsLine);
86  m_customPlot->graph()->setPen(pen);
87  m_customPlot->graph()->setBrush(QBrush(QColor(255 / 4, 160, 50, 150)));
88 
89  auto base_size = GUI::Util::Style::SizeOfLetterM();
90  auto* axisRectangle = m_customPlot->axisRect();
91  axisRectangle->setAutoMargins(QCP::msTop | QCP::msBottom);
92  axisRectangle->setMargins(QMargins(base_size.width() * 4, base_size.height() * 2,
93  base_size.width() * 2, base_size.height() * 2));
94 }
Defines class HistogramPlot.
Defines various constants for plotting.
void addData(double x, double y)
QCustomPlot * m_customPlot
Definition: HistogramPlot.h:35
HistogramPlot(QWidget *parent=nullptr)
void setData(const QVector< double > &x, const QVector< double > &y)
int plot_tick_label_size()
Definition: PlotConstants.h:23
int plot_axes_label_size()
Definition: PlotConstants.h:28
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:113