QCustomPlot Discussion and Comments

Implementing QCPColorMapData with a 2-D arrayReturn to overview

Hello,

I would like to know if it's possible to enter a 2D array (my_data[][]) directly when creating my instance of a QCPColorMapData instead of looping twice (on x-Axis and y-Axis) and using setCell?

Thanks, and sorry for my bad english, i'm french

Stef

Hi,

I think you can not. By looking at the description of the class members, there seem to be only methods for setting data in a cell by cell manner.

Best regards

Hi, someone may need this solution in 2019 :)

Add the replaceMap function below to the QCPColorMapData class.

void replaceMap(double *newMap)
{ 
    mData = newMap; 
    mDataModified = true;
}

Prepare your map data as 1D array.

double my_data[row*column];

Set element to your 1D array as show below.

void setElement(int x, int y, double z)
{
    my_data[x*column + y] = z;
}

Replace the map data.

m_colorMap->data()->replaceMap(my_data);

That method you posted is a bit dangerous, because it never adapts or checks the size of the passed array...