BornAgain  1.19.0
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/coregui/Views/FitWidgets/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 
18 HistogramPlot::HistogramPlot(QWidget* parent) : QWidget(parent), m_customPlot(new QCustomPlot)
19 
20 {
21  QVBoxLayout* vlayout = new QVBoxLayout(this);
22  vlayout->setMargin(0);
23  vlayout->setSpacing(0);
24  vlayout->setContentsMargins(0, 0, 0, 0);
25  vlayout->addWidget(m_customPlot);
26  setLayout(vlayout);
27  setStyleSheet("background-color:white;");
28 
29  initGraph();
30 
31  m_customPlot->xAxis->setTickLabelFont(
32  QFont(QFont().family(), Constants::plot_tick_label_size()));
33  m_customPlot->yAxis->setTickLabelFont(
34  QFont(QFont().family(), Constants::plot_tick_label_size()));
35 
36  m_customPlot->yAxis->setScaleType(QCPAxis::stLogarithmic);
37  m_customPlot->yAxis->setNumberFormat("eb");
38  m_customPlot->yAxis->setNumberPrecision(0);
39 
40  m_customPlot->xAxis->setLabel("iteration");
41  m_customPlot->yAxis->setLabel("chi2");
42 
43  m_customPlot->xAxis->setLabelFont(QFont(QFont().family(), Constants::plot_axes_label_size()));
44  m_customPlot->yAxis->setLabelFont(QFont(QFont().family(), Constants::plot_axes_label_size()));
45 }
46 
47 void HistogramPlot::addData(double x, double y)
48 {
49  m_customPlot->graph()->addData(x, y);
50  m_customPlot->graph()->rescaleAxes();
51  m_customPlot->replot();
52 }
53 
54 void HistogramPlot::addData(const QVector<double>& x, const QVector<double>& y)
55 {
56  m_customPlot->graph()->addData(x, y);
57  m_customPlot->graph()->rescaleAxes();
58  m_customPlot->replot();
59 }
60 
61 void HistogramPlot::setData(const QVector<double>& x, const QVector<double>& y)
62 {
63  m_customPlot->graph()->setData(x, y);
64  m_customPlot->graph()->rescaleAxes();
65  m_customPlot->replot();
66 }
67 
69 {
70  m_customPlot->removeGraph(m_customPlot->graph());
71  initGraph();
72  m_customPlot->replot();
73 }
74 
76 {
77  m_customPlot->addGraph();
78 
79  QPen pen(QColor(0, 0, 255, 200));
80  m_customPlot->graph()->setLineStyle(QCPGraph::lsLine);
81  m_customPlot->graph()->setPen(pen);
82  m_customPlot->graph()->setBrush(QBrush(QColor(255 / 4, 160, 50, 150)));
83 
84  auto base_size = StyleUtils::SizeOfLetterM();
85  auto axisRectangle = m_customPlot->axisRect();
86  axisRectangle->setAutoMargins(QCP::msTop | QCP::msBottom);
87  axisRectangle->setMargins(QMargins(base_size.width() * 4, base_size.height() * 2,
88  base_size.width() * 2, base_size.height() * 2));
89 }
Defines class HistogramPlot.
void addData(double x, double y)
HistogramPlot(QWidget *parent=0)
QCustomPlot * m_customPlot
Definition: HistogramPlot.h:35
void setData(const QVector< double > &x, const QVector< double > &y)
int plot_tick_label_size()
int plot_axes_label_size()
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:110
Defines various constants for plotting.