PDA

View Full Version : Multiple legends with single plot?



SeanM
30th April 2014, 20:20
I'm wondering if it's possible to have multiple legends connected to a single plot, but have the legends show different curves? And if so, the obvious follow up is how to go about doing it...

I've got a setup where the user can choose to display 1-16 curves per plot. Each individual curve has completely different range values, some go from 0 to 12,000, others go from 0 to 1, others go from -127 to +128, etc. So right now I've got it set up where I'm using both the right and left axes, with the left axis reserved for "big" value ranges (like the 0 to 12,000 curve) and the right axis for smaller ranges (like to 0 to 1). I'm currently using a single legend to the right of the plot. As I've been playing around with it and showing it to coworkers, we're in agreement that it's confusing that some of the curves are using the left axis, some are using the right axis, but all of the curves are showing up in the single legend to the right.

So I'd like to have a horizontal layout that looks like:
| left legend | left axis | plot | right axis | right legend |

Where the curves that are using the left axis only show up in the left legend, and curves that are using the right axis only show up in the right legend

Uwe
2nd May 2014, 08:57
Te layout system of QwtPlot is not able to handle more than one legend, but you can have as many legends as you want to, when you are willing to take care of their layouts yourself. On screen this is easy using standard Qt layouts, but when using QwtPlotRenderer you might need to implement some layout code yourself.

Instead of using QwtPlot::insertLegend you have to handle the QwtPlot::legendDataChanged() signal yourself. By overloading QwtPlotItem::legendData() you could add some extra information to the legend data, so that you know later what item goes to what legend.

Uwe