In the .__init__()
for this class, I have the lines:
class report_order_totals_by_photographer(wx.Panel):
def __init__(...):
...
self.figure = matplotlib.figure.Figure()
self.canvas = matplotlib.backends.backend_wxagg.FigureCanvasWxAgg(panel_canvas, -1, self.figure)
And in an event handler I have:
self.figure.clf()
datapoints = range(len(self.data))
values = [x[1] for x in self.data]
labelpositions = [x + 0.5 for x in range(len(self.data))]
labeltext = [x[0] for x in self.data]
bars = matplotlib.pyplot.barh(datapoints, values)
labels = matplotlib.pyplot.yticks(labelpositions, labeltext)
self.figure.artists.extend(bars)
self.figure.axes.extend(labels)
self.canvas.draw()
Which looks like this:
https://i.stack.imgur.com/Br7vW.png
Or this when resized:
https://i.stack.imgur.com/wnMku.png
Which is confusing and frustrating. I want it to look something like this:
data = db.get_order_totals_for_photographers(*season_to_dates("14w"))
import matplotlib.pyplot as plt
plt.barh(range(len(data)), [x[1] for x in data])
plt.yticks([x + 0.5 for x in range(len(data))], [y[0] for y in data])
plt.show()
i.imgur.com/BD1RXOq.png
(Which is also confusing and frustrating, 'cause the names extend off the page, but whatever, I can care about that later).
My main two problems are that it's not resizing with the frame it's in, and that I can only draw the bars, and nothing else.
In my working example, I'm using what the matplotlib tutorial calls a "thin stateful wrapper around matplotlib's API", which weirds me out, and I don't like it. Luckily, the tutorial follows up with: "If you find this statefulness annoying, don't despair, this is just a thin stateful wrapper around an object oriented API, which you can use instead (See Artist tutorial)". In the artist tutorial, there's very little useful information which I could use, but a couple hints, that lead me to self.figure.artists.extend(bars)
.
I've had slightly more success with self.figure.texts.extend(labels[1])
, but that just piles all the names on top of eachother, (and I think the ticks are piled on top of eachother right of the plot), so I'm still clueless.
Any help would be greatly appreciated.