QCustomPlot Discussion and Comments

Zoom background image and set background reference to coordintesReturn to overview

Hi guys,
please help me out in solving,
1.) My back ground image should be fixed to center of the coordinates, now if I zoom the background, the background image should zoom along with my axis.

setInteractions is zooming only the coordinates with out taking the background image into consideration.

The QCustomPlot or axis rect background is not fixed to plot coordinates by definition. If you want an image that zooms with your data, you should use QCPItemPixmap instead, and fix the respective topLeft/bottomRight positions of that item to plot coordinates (see the documentation and examples for how to work with items, in case you're new to them).

Hi, Ravindra!

1) You are to anchor topLeft & bottomRight corners of the image to the xAxis and yAxis ranges
2) Set you image (QCPItemPixmap) to be scalable

QCPItemPixmap *MyImage = new QCPItemPixmap(customPlot);
MyImage->topLeft->setCoords(customPlot->xAxis->range().lower, customPlot->yAxis->range().upper);
MyImage->bottomRight->setCoords(customPlot->xAxis->range().upper, customPlot->yAxis->range().lower);

I'm wanting to do the same thing as the one who started the thread.. However, I am not able to find an "addItem" function when I access my plot.. Could anyone help me with my problem? Thanks

addItem isn't needed anymore, since QCustomPlot 2.0. You can just leave it away.

I tried removing line 9, and also set the visibility for the image, but no image is rendered.
Do you know what the problem might be?

    QCPItemPixmap *MyImage = new QCPItemPixmap(ui -> mapPlot);
MyImage->topLeft->setCoords(ui -> mapPlot->xAxis->range().lower, ui -> mapPlot->yAxis->range().upper);
MyImage->bottomRight->setCoords(ui -> mapPlot->xAxis->range().upper, ui -> mapPlot->yAxis->range().lower);

customPlotHandle->yAxis->setRange(0, 300);
    customPlotHandle->xAxis->setRange(400, 800);
QCPItemPixmap *MyImage = new QCPItemPixmap(ui->spectraPlot);
	MyImage->topLeft->setCoords(ui->spectraPlot->xAxis->range().lower, ui->spectraPlot->yAxis->range().upper);
	MyImage->bottomRight->setCoords(ui->spectraPlot->xAxis->range().upper, ui->spectraPlot->yAxis->range().lower);
	MyImage->setScaled(true, Qt::IgnoreAspectRatio);

This is my current code, i need to set background image for xaxis range(400:800) . But in this it also needs yaxis range. for now i have just set it to maximum.
But problem it takes longer time process if axis range changes.
Can you point me to an example where 2 graphs are added to same plot ,
graph(0) for background Image and
graph(1) for data.