I thought this would be straight forward, since the instructions on this are quite clear, but my implementation varies sufficiently from the original that I have now gotten myself into a little confusion!
I have a class called MplCanvas:
class MplCanvas(FigureCanvasTkAgg):
def __init__(self, parent=None, width = 7, height = 6, dpi = 100):
fig = Figure(figsize = (width, height), dpi = dpi)
self.axs = fig.add_subplot(111) # Create a subplot as a single plot
super().__init__(fig, parent)
I then define an object of this class:
class GraphFrame(customtkinter.CTkFrame):
def __init__(self, *args, graph = 0, **kwargs):
super().__init__(*args, **kwargs)
self.sc = MplCanvas(self, width = 7, height = 6, dpi = 100)
And then I use this within this new class. For example…
def cm_graph(self, filenames):
sa_sun = 4 * self.PI * math.pow(self.R_SUN, 2) # Solar surface area
t_sun = self.L_SUN / (sa_sun * self.SIGMA) # Solar surface temperature
for index, filename in enumerate(filenames): # Loop through each file
linename = Path(filename)
stellarData = self.readData(filename) # Read STELCOR data from file
colour = self.colours[index % 5] # Identify the colour for this particular file's data
line = self.lines[index // 4] # Define the line style to be used for this file's data
l_star = stellarData[:, 4] / self.L_SUN # Calculate the ratio between the star's luminosity and our Sun's
r_star = np.power(stellarData[:, 3] / self.R_SUN, 2) # Calculate the ratio between the star's radius and our Sun's
t_star = np.power((t_sun * l_star) / r_star, 0.25) # Calculates the temperature of the star
self.sc.axs.loglog(t_star[:], l_star[:], color = colour, \
linestyle = line, label = linename.stem) # Create a loglog plot of this file's data
self.sc.axs.set_title(r'Temperature Magnitude (TM) Diagram')
self.sc.axs.set_xlabel(r'Surface Temperature (Kelvin) - ${(\frac{t_{\odot} \times L_{\star}}{R_{\odot}})}^\frac{1}{4}$')
self.sc.axs.set_ylabel(r'Luminosity (Solar Units) - $\frac{L_{\star}}{L_{\odot}}$')
self.sc.axs.invert_xaxis()
self.sc.axs.legend()
self.sc.get_tk_widget().grid(row = 0, column = 0)
self.sc.draw()
However, I now want to add a toolbar to this frame. I have tried adding it to the object (self.sc) but this generates an (obvious) error. I can’t reference the fig that is within MplCanvas directly and not sure this would help anyway.
What am I missing (aside from a brain)?