3

I was playing with boxplot (and bxp) in Python. For integretion with pyQt I used code from matplotlib example and stack. When I'm drawing boxplot in popup, it works fine. When I try to draw some simple plot on the canvas in pyQt (like sin, or like in the examples above), it works fine.

The problem is when i try to draw boxplot on my canvas in pyQt window, only fliers are shown.

Am I doing something wrong? Is there other way to show boxplot in pyQt window?

It looks like this: enter image description here

My code -s 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()

Overrided plot method from stack answer:

    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()
Community
  • 1
  • 1
Kocik
  • 494
  • 2
  • 17

1 Answers1

1

Hey I've searched for solutions but could not find any good hint. But then I tried to play a little bit with the code. And somehow it works now (the problem is the line ax.hold(False):

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 call hold AFTER 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 fine ;) I hope I could help you with this answer.

ProgrammingIsAwsome
  • 1,109
  • 7
  • 15