lloydd4 lloydd4 - 1 month ago 15
Python Question

Title in matlab graph subplot

I've created a matlab graph in my Tkinter GUI. Which is part of a bigger GUI class. I'm having issues with adding a title.

Question: Does anyone know how I give my subplots a title ?

self.f = plt.Figure(figsize=(4,5), dpi=90)

self.a = self.f.add_subplot(211)
self.a.plot([1, 2, 3, 4, 5, 6, 7, 8], [5, 6, 1, 7, 4, 2, 5, 0])
self.a.plt.ylabel('some numbers')

self.b = self.f.add_subplot(212)
self.b.plot([1, 2, 3, 4, 5, 6, 7, 8], [1, 3, 6, 1, 0, 2, 1, 0])

self.canvas = FigureCanvasTkAgg(self.f, master=self.frame1)
self.canvas.get_tk_widget().grid(row=8, column=0, columnspan=2)


Simply adding the following code doesn't work.

self.a.plt.title('some numbers')

Answer

This is an example from matplotlib

Matplotlib has standards I haven't quite fully comprehended yet, but it seems that which method you use to do something like set a title depends on if you're using a fig, plot, or axis...in this case, the answer is:

self.a.set_title('title goes here for your subplot')
Comments