QCustomPlot Discussion and Comments

QCP 2.0.0: Plottable rescaleValueAxis method (and getValueRange) Return to overview

Hi and thanks for this great api.

I am QT newbie and I have a humble question. I can not figure out how to code rescaleValueAxis inKeyRange mentioned in change log:

"Plottable rescaleValueAxis method (and getValueRange) now take parameter inKeyRange, which allows rescaling of the value axis only with respect to data in the currently visible key range"

Is there some example or could someone provide simple example?

Thanks in advance

Here is how I do it for multiple graphs:

//!set new y-range
double y_lower = 0;
double y_upper = 0;

//!get current xaxis.range
double x_axis_range_lower = w->xAxis->range().lower;
double x_axis_range_upper = w->xAxis->range().upper;

//iterate through graph(i) data keys and values

for (int i = 0; i < w->graphCount(); ++i) {
	QCPGraphDataContainer::const_iterator it = w->graph(i)->data()->constBegin();
	QCPGraphDataContainer::const_iterator itEnd = w->graph(i)->data()->constEnd();
	while (it != itEnd)
	  if (it->key >= x_axis_range_lower && it->key <= x_axis_range_upper ){
		  if (it->value <= y_lower ){
			  y_lower = it->value;
			  qWarning() << "y_lower:" << y_lower;
		  if (it->value >= y_upper ){
			  y_upper = it->value;
			   qWarning() << "y_upper:" << y_upper;


//set y-range
w->yAxis->setRange(y_lower, y_upper*1.2);

Hi Mara,
I'm another newbie, but I added the following and it seems to be doing the right thing:

ui->customPlot->graph(0)->rescaleValueAxis(false, true);

Here customPlot is the name of the central widget in my application. I guess you can call this for each of your graph(i)?

In my case I call the rescaleValueAxis as part of a signal-slot:

connect(ui->customPlot->xAxis,    SIGNAL(rangeChanged(QCPRange)), this,   SLOT(onXRangeChanged()));

void MainWindow::onXRangeChanged()
    ui->customPlot->graph(0)->rescaleValueAxis(false, true);