Greetings,
I am hoping someone can help with this simple problem. I am trying to toggle the visibility of the legend of a plot but nothing seems to work.
I have tried the following but nothing happens. The legend just remains visible:
plot.legend().setVisible(False)/plot.legend().setVisible(True)
plot.legend().hide()/plot.legend().show()
plot.legend().setVisible(False)/plot.legend().setVisible(True)
plot.legend().hide()/plot.legend().show()
To copy to clipboard, switch view to plain text mode
I have tried:
plot.legend().contentsWidget().setVisible(False)/plot.legend().contentsWidget().setVisible(True)
plot.legend().contentsWidget().setVisible(False)/plot.legend().contentsWidget().setVisible(True)
To copy to clipboard, switch view to plain text mode
but this just hides the clickable legend items, the box of the legend is still visible which is not what I want. I would like the entire legend to appear or disappear.
I have also tried keeping the legend around in my class after I create it by going:
#insert legend into plot here
self.plotLegend=QwtLegend()
#insert legend into plot here
To copy to clipboard, switch view to plain text mode
Then, to make the legend “not visible†I remove it by calling
plot.insertLegend(None)
plot.insertLegend(None)
To copy to clipboard, switch view to plain text mode
but then when I try to reinsert my legend to make it “visible†again:
plot.insertLegend(self.plotLegend, locationNotImportant)
plot.insertLegend(self.plotLegend, locationNotImportant)
To copy to clipboard, switch view to plain text mode
I get an error stating the underlying C++ object has been deleted.
Is there seriously no way to do this without creating a new legend every time? This would seem to be so simple…
Any help is appreciated, thank you.
(Using PyQwt 5.1.0)
Bookmarks