QCustomPlot Discussion and Comments


I try to create an iteractive heatmap. There are 20000 rectangles with different colors. I have implemented this heatmap with 2000 QCPItemRect but it is very slow.

Is there an other way to display a heatmap ? If QCPItemRect is the right mean, is there a way to prepare all the rectangles and then display it all at once ?

Thanks !


By using a parametric curve (demo graph: http://www.qcustomplot.com/images/examples/parametriccurvesdemo.png ) you could create the boundaries of the heat and then color with a semi-transparent color the inside of the boundaries. By overlapping many boundaries you could get the different heat zones. You wouldn't get smooth heat transitions but rather different color zones with a range of heats represented by the same color (such as 100° to 200° represented by the same orange color instead of smooth transition from a yellow 100° to a red 200°).

Fact is, such smooth heat color transitions that are usually seen in heat graphs are not possible by default in QCP since there is no function that would do that. Another user wanted to use something similar for a DSP graph and had the same limitation.
My best suggestion is to use QCP just for graph details like legend, axis, act.. but for the graph itself you might want to get dirty with reimplementing the draw function and using plain QPainter drawing.

For Emanuel (DerManu), it looks quite obvious to me that QCP needs something to help for these type of graphs, can you look forward to this?

As to be expected, 20000 rectangle items will be slow, as will probably be QCPCurve plottables emulating the shades.

I'm aware that a 2D map/vector plot is much desired, and I have a branch that already has such a 2D map plottable. However, I'm not happy with its interface yet. It will definitely come in one of the next releases, though.

Thank you for your answers.

I avoided the problem by changing the QCPLayerable::setVisible() method from protected to public, and then creating a parent rectangle for the heatmap that is set to invisible.

Then, I create each rectangles of the heatmap as children of the parent invisible rectangle. I set the pen to the desired color at each insertion.

At the end of the addition of the rectangles, I set the parent to visible.

Furthermore, my process is iterative, at each iteration of the algorithm described, the colors need to be updated. To avoid a slow refreshing, I store an array of pointers to the rectangles, and just update the colors with the pen.

With this method, I don't have any slowing problem in my heatmap anymore.