21 #include "ui_plotwidget.h" 39 colors_ = {QColor(228,26,28),
56 QColor pen_color = this->GetNextColor();
58 if (paired_data.n_cols < 2)
61 qvec::fromStdVector(conv_to<stdvec>::from(paired_data.col(0)));
63 qvec::fromStdVector(conv_to<stdvec>::from(paired_data.col(1)));
64 int graph_count = ui->customPlot->graphCount();
66 ui->customPlot->addGraph();
67 ui->customPlot->graph(graph_count)->addData(abscissa, data);
70 ui->customPlot->addGraph(ui->customPlot->graph(0)->keyAxis(), ui->customPlot->graph(0)->valueAxis());
71 ui->customPlot->graph(graph_count)->addData(abscissa, data);
73 ui->customPlot->graph(graph_count)->setPen(pen);
74 ui->customPlot->rescaleAxes();
80 QColor pen_color = this->GetNextColor();
83 qvec::fromStdVector(conv_to<stdvec>::from(abscissa));
85 qvec::fromStdVector(conv_to<stdvec>::from(data));
86 int graph_count = ui->customPlot->graphCount();
88 ui->customPlot->addGraph();
89 ui->customPlot->graph(graph_count)->addData(abscissa_qvec, data_qvec);
92 ui->customPlot->addGraph(ui->customPlot->graph(0)->keyAxis(), ui->customPlot->graph(0)->valueAxis());
93 ui->customPlot->graph(graph_count)->addData(abscissa_qvec, data_qvec);
95 ui->customPlot->graph(graph_count)->setPen(pen);
96 ui->customPlot->rescaleAxes();
102 QColor pen_color = this->GetNextColor();
104 if (abscissa.n_rows != data.n_rows)
return;
106 if (transient_graph_){
108 qvec::fromStdVector(conv_to<vector<double> >::from(abscissa));
110 qvec::fromStdVector(conv_to<vector<double> >::from(data));
111 transient_graph_->
setData(abscissa_qvec, data_qvec);
116 if (ui->customPlot->graphCount()){
117 key_axis = ui->customPlot->graph(0)->keyAxis();
118 value_axis = ui->customPlot->graph(0)->valueAxis();
124 ui->customPlot->addGraph(key_axis, value_axis);
125 transient_graph_ = ui->customPlot->graph(ui->customPlot->graphCount() - 1);
127 qvec::fromStdVector(conv_to<vector<double> >::from(abscissa));
129 qvec::fromStdVector(conv_to<vector<double> >::from(data));
130 transient_graph_->
addData(abscissa_qvec, data_qvec);
132 transient_graph_->
setPen(pen);
133 ui->customPlot->rescaleAxes();
139 QColor pen_color = this->GetNextColor();
142 if (paired_data.n_cols != 2)
return;
146 if (transient_graph_){
148 qvec::fromStdVector(conv_to<vector<double> >::from(paired_data.col(0)));
150 qvec::fromStdVector(conv_to<vector<double> >::from(paired_data.col(1)));
151 transient_graph_->
setData(abscissa_qvec, data_qvec);
154 if (ui->customPlot->graphCount()){
155 key_axis = ui->customPlot->graph(0)->keyAxis();
156 value_axis = ui->customPlot->graph(0)->valueAxis();
162 ui->customPlot->addGraph(key_axis, value_axis);
163 transient_graph_ = ui->customPlot->graph(ui->customPlot->graphCount() - 1);
165 qvec::fromStdVector(conv_to<vector<double> >::from(paired_data.col(0)));
167 qvec::fromStdVector(conv_to<vector<double> >::from(paired_data.col(1)));
168 transient_graph_->
addData(abscissa_qvec, data_qvec);
170 transient_graph_->
setPen(pen);
171 ui->customPlot->rescaleAxes();
181 QColor pen_color = this->GetNextColor();
183 if (paired_data.n_cols < 2)
186 qvec::fromStdVector(conv_to<stdvec>::from(paired_data.col(0)));
188 qvec::fromStdVector(conv_to<stdvec>::from(paired_data.col(1)));
189 int graph_count = ui->customPlot->graphCount();
190 if (graph_count < 1){
191 ui->customPlot->addGraph();
192 ui->customPlot->graph(graph_count)->addData(abscissa, data);
195 ui->customPlot->addGraph(ui->customPlot->graph(0)->keyAxis(), ui->customPlot->graph(0)->valueAxis());
196 ui->customPlot->graph(graph_count)->addData(abscissa, data);
198 ui->customPlot->graph(graph_count)->setPen(pen);
201 ui->customPlot->graph(graph_count)->setScatterStyle(style);
203 ui->customPlot->rescaleAxes();
214 QColor pen_color = this->GetNextColor();
216 qvec::fromStdVector(conv_to<stdvec>::from(abscissa));
218 qvec::fromStdVector(conv_to<stdvec>::from(data));
219 int graph_count = ui->customPlot->graphCount();
220 if (graph_count < 1){
221 ui->customPlot->addGraph();
222 ui->customPlot->graph(graph_count)->addData(abscissa_qvec, data_qvec);
225 ui->customPlot->addGraph(ui->customPlot->graph(0)->keyAxis(), ui->customPlot->graph(0)->valueAxis());
226 ui->customPlot->graph(graph_count)->addData(abscissa_qvec, data_qvec);
230 ui->customPlot->graph(graph_count)->setScatterStyle(style);
232 ui->customPlot->rescaleAxes();
244 if (categorical.n_rows != paired_data.n_rows){
249 vec unique_values = unique(categorical);
251 for (uword i = 0; i < unique_values.n_rows; ++i){
253 while (color_index >= colors_.size()){color_index -= colors_.size();}
254 QColor color = colors_[color_index];
256 double value = unique_values(i);
257 uvec indices = arma::find(categorical == value);
258 mat current_data = paired_data.rows(indices);
259 qvec x = qvec::fromStdVector(conv_to<stdvec>::from(current_data.col(0)));
260 qvec y = qvec::fromStdVector(conv_to<stdvec>::from(current_data.col(1)));
262 int graph_count = ui->customPlot->graphCount();
263 if (graph_count < 1){
264 ui->customPlot->addGraph();
265 ui->customPlot->graph(graph_count)->addData(x, y);
268 ui->customPlot->addGraph(ui->customPlot->graph(0)->keyAxis(), ui->customPlot->graph(0)->valueAxis());
269 ui->customPlot->graph(graph_count)->addData(x, y);
272 ui->customPlot->graph(graph_count)->setScatterStyle(style);
275 ui->customPlot->rescaleAxes();
287 if (data.n_rows != abscissa.n_rows)
return;
289 if (categorical.n_rows != data.n_rows){
294 vec unique_values = unique(categorical);
296 for (uword i = 0; i < unique_values.n_rows; ++i){
298 while (color_index >= colors_.size()){color_index -= colors_.size();}
299 QColor color = colors_[color_index];
301 double value = unique_values(i);
302 uvec indices = arma::find(categorical == value);
303 vec current_data = data.rows(indices);
304 vec current_abscissa = abscissa.rows(indices);
305 qvec x = qvec::fromStdVector(conv_to<stdvec>::from(current_abscissa));
306 qvec y = qvec::fromStdVector(conv_to<stdvec>::from(current_data));
308 int graph_count = ui->customPlot->graphCount();
309 if (graph_count < 1){
310 ui->customPlot->addGraph();
311 ui->customPlot->graph(graph_count)->addData(x, y);
314 ui->customPlot->addGraph(ui->customPlot->graph(0)->keyAxis(), ui->customPlot->graph(0)->valueAxis());
315 ui->customPlot->graph(graph_count)->addData(x, y);
318 ui->customPlot->graph(graph_count)->setScatterStyle(style);
322 ui->customPlot->rescaleAxes();
328 if (transient_graph_){
329 ui->customPlot->removeGraph(transient_graph_);
330 transient_graph_ = 0;
331 ui->customPlot->rescaleAxes();
338 return (transient_graph_ && ui->customPlot->graphCount() == 1);
346 QColor PlotWidget::GetNextColor()
350 int color_index = ui->customPlot->graphCount();
351 while (color_index >= colors_.size()){color_index -= colors_.size();}
352 return colors_[color_index];
0x001 Axis ranges are draggable (see QCPAxisRect::setRangeDrag, QCPAxisRect::setRangeDragAxes) ...
0x080 All other objects are selectable (e.g. your own derived layerables, the plot title...
0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) ...
0x040 Items are selectable (Rectangles, Arrows, Textitems, etc. see QCPAbstractItem) ...
Manages a single axis inside a QCustomPlot.
Represents the visual appearance of scatter points.
0x004 The user can select multiple objects by holding the modifier set by QCustomPlot::setMultiSelect...
void setPen(const QPen &pen)
0x020 Legends are selectable (or their child items, see QCPLegend::setSelectableParts) ...
{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle) ...
The QCustomPlot surface is immediately refreshed, by calling QWidget::repaint() after the replot...
0x002 Axis ranges are zoomable with the mouse wheel (see QCPAxisRect::setRangeZoom, QCPAxisRect::setRangeZoomAxes)
void setData(QCPDataMap *data, bool copy=false)
void addData(const QCPDataMap &dataMap)
bool SavePlot(QCustomPlot *plot, QString filename)
Vespucci::SavePlot.