Boxplot not showing when used with pyQt
I've been playing around with boxplot (and bxp) in Python. To merge with pyQt I used the matplotlib and stack example code . When I draw the boxplot in the popup it works fine. When I try to draw some simple plot to canvas in pyQt (like sin or like in the examples above) it works fine.
The problem is when I try to draw a boxplot on my canvas in the pyQt window, only the flyers are displayed.
Am I doing something wrong? Is there any other way to show boxplot in pyQt window?
It looks like this:
My code is tandalone version
import matplotlib.pyplot as plt
data = [{'med': 6.0, 'q1': 4.0, 'q3': 8.0, 'whislo': 3.0, 'whishi': 10.0, 'fliers': [20, 1]}]
fig, axes = plt.subplots()
axes.bxp(data)
plt.show()
The overridden section method from the answer stack :
data = [{'med': 6.0, 'q1': 4.0, 'q3': 8.0, 'whislo': 3.0, 'whishi': 10.0, 'fliers': [20, 1]}]
ax = self.figure.add_subplot(111)
ax.hold(False)
ax.bxp(data)
self.canvas.draw()
source to share
Hey I was looking for solutions but couldn't find any good hint. But then I tried to play around with the code a bit. And somehow it works now (the problem is in the ax.hold (False) line:
If you call it like this (code from your question):
data = [{'med': 6.0, 'q1': 4.0, 'q3': 8.0, 'whislo': 3.0, 'whishi': 10.0, 'fliers': [20, 1]}]
ax = self.figure.add_subplot(111)
ax.hold(False) // call hold BEFORE bxp(data)
ax.bxp(data)
self.canvas.draw()
This does not work. But now keep the AFTER call bxp (data) and it works (I tested it and it worked).
data = [{'med': 6.0, 'q1': 4.0, 'q3': 8.0, 'whislo': 3.0, 'whishi': 10.0, 'fliers': [20, 1]}]
ax = self.figure.add_subplot(111)
ax.bxp(data)
ax.hold(False) // call hold AFTER bxp(data)
self.canvas.draw()
The second version works great;) Hope I can help you with this answer.
source to share