Hello everyone!
I use QCustomPlot to draw my graphs and I tried different methods and nothing seems to give me the result I search.
I want to draw multiple graphs, one below the other. The separation between each graph should be the same for all of them.
I also want to be able to change the scale of both the x- and y-axis, keeping the origin of each graph the same (their "0" shouldn't move when rescaling the y-axis). Which also mean that each graph could overlap with the others if needed (this also mean that it can happen that data can go out of the screen, but that's ok).
For the x-axis, I don't have a problem, its quite easy. Its the rescaling of the y-axis that gives me problems...
So here's what I've got for now:
In this first code, I'm able to fix the position of each plot, but I don't see how to change the y-axis scale during execution.
plot = new QCustomPlot;
xAxis.resize(timeScale);
for (int i = 0; i < timeScale; i++)
{
xAxis[i] = i;
}
// Offset the data so they're not on top of each other
//--------------------
QCPRange defaultRange(-100., 100.);
for (int i = 0; i < nbPlot; i++)
{
QCPAxis *axis = plot->axisRect()->addAxis(QCPAxis::atLeft);
axis->setRange(defaultRange.lower - (nbPlot - 1 - i) * defaultRange.size(),
defaultRange.upper + i * defaultRange.size());
axis->setVisible(false);
QCPGraph *graph = new QCPGraph(plot->xAxis, axis);
}
// Set the data to the plot
//--------------------
for (int i = 0; i < plot->graphCount(); i++)
{
plot->graph(i)->setData(xAxis, plotMatrix[i], true);
}
plot = new QCustomPlot;
xAxis.resize(timeScale);
for (int i = 0; i < timeScale; i++)
{
xAxis[i] = i;
}
// Offset the data so they're not on top of each other
//--------------------
QCPRange defaultRange(-100., 100.);
for (int i = 0; i < nbPlot; i++)
{
QCPAxis *axis = plot->axisRect()->addAxis(QCPAxis::atLeft);
axis->setRange(defaultRange.lower - (nbPlot - 1 - i) * defaultRange.size(),
defaultRange.upper + i * defaultRange.size());
axis->setVisible(false);
QCPGraph *graph = new QCPGraph(plot->xAxis, axis);
}
// Set the data to the plot
//--------------------
for (int i = 0; i < plot->graphCount(); i++)
{
plot->graph(i)->setData(xAxis, plotMatrix[i], true);
}
To copy to clipboard, switch view to plain text mode
In this second code, I offset the data, and I'm able to dynamically change the y-axis during execution. But the graphs's origins aren't fixed, and move when rescaling.
plot = new QCustomPlot;
xAxis.resize(timeScale);
for (int i = 0; i < timeScale; i++)
{
xAxis[i] = i;
}
// Set the data to the plot
//--------------------
for (int i=0; i<nbPlot; ++i)
{
plot->addGraph();
// Offset data:
for (int j = 0; j < plotMatrix[i].length(); j++)
{
plotMatrix[i][j] -= (i + 1) * 200;
}
plot->graph()->setData(xAxis, plotMatrix[i]);
plot->graph()->rescaleAxes(true);
}
plot = new QCustomPlot;
xAxis.resize(timeScale);
for (int i = 0; i < timeScale; i++)
{
xAxis[i] = i;
}
// Set the data to the plot
//--------------------
for (int i=0; i<nbPlot; ++i)
{
plot->addGraph();
// Offset data:
for (int j = 0; j < plotMatrix[i].length(); j++)
{
plotMatrix[i][j] -= (i + 1) * 200;
}
plot->graph()->setData(xAxis, plotMatrix[i]);
plot->graph()->rescaleAxes(true);
}
To copy to clipboard, switch view to plain text mode
In both cases, the graphs can overlap with the other if the data ask for it. But none of those codes satisfy my needs...
If you have any advice on how to make it or even code example, I'll take it ^^
Have a good day!
Bookmarks