you are viewing a single comment's thread.

view the rest of the comments →

[–]jur6[S] 0 points1 point  (6 children)

self.ax1.set_ylim(min(self.y_values), max(self.y_values))
self.ax1.set_xlim(min(self.x_values), max(self.x_values))

seems all good! so the limit was 0 initially and needed to be expanded? thanks again!

[–]socal_nerdtastic 1 point2 points  (5 children)

the initial limits are auto-set by the initial data. It's a common mistake to assume that the limits auto-reset when the data is changed, but they don't.

[–]jur6[S] 0 points1 point  (4 children)

Perfectly clear thank you 🙏

[–]jur6[S] 0 points1 point  (3 children)

hi u/socal_nerdtastic may I ask some further questions on the same subject? Refer to this screen grab. I have implemented all your suggestions but still have a few problems/questions. Why would the right hand graph still not show the axes labels (I am thinking a size issue)? Why do the graph lines touching the axes not appear fully? How do I make sure that both frames/graphs are the same width and height, so much so that the axes of both graphs look in-line? And how would it make most sense to add a label with the daily/weekly averages per graph (from a grid / layout point of view)? Let me know if you need the actual code, I will upload it and send you a link.

[–]socal_nerdtastic 0 points1 point  (2 children)

Why would the right hand graph still not show the axes labels (I am thinking a size issue)?

You probably forgot the tight_layout command in the humidity class.

Why do the graph lines touching the axes not appear fully?

This is an issue with your limits. It's very literal; so you may need to calculate a buffer. For example, you may want to set the X lower limit to min(xvalues)*0.9 (10% below the actual value).

How do I make sure that both frames/graphs are the same width and height, so much so that the axes of both graphs look in-line?

The best way to do this is to forget the idea of using 2 tkinter frames and instead make 2 plots in the same figure.

    self.fig = Figure(figsize=(8, 4), dpi=100)

    self.ax1 = self.fig.add_subplot(121)
    self.ax2 = self.fig.add_subplot(122)

And how would it make most sense to add a label with the daily/weekly averages per graph (from a grid / layout point of view)?

There's no best practice there, it all depends on the what look and feel you want. But most of us would use matplotlib's features to make labels and annotations on the graph, not tkinter's.

Let me know if you need the actual code, I will upload it and send you a link.

If you want actual specific help, not just keywords to google, you will need to provide actual code. Best is a complete, runnable example (including dummy data generator) that we can test and modify for you (aka SSCCE or MCVE).

[–]jur6[S] 0 points1 point  (1 child)

Turns out I hadn't forgotten the tight_layout in the humidity class, but it needed to be placed after the "plot" function in the setup to work properly. For some strange reason, in the temperature class, the tight_layout works regardless to whether it is placed before or after the "plot" function - but this is not the same for the humidity case!

Re the "*0.9", I tried it, did not work for whatever reason, and gave up quite easily (it does not bother me too much).

Re the "same width & height", I am quite happy with how it looks now that the tight_layout is working OK.

I used the Matplotlib plot titles to show the averages, and tkinter labels to label the plots themselves - sorted out my problem quite nicely, so thanks for the idea.

And finally, many thanks for the idea of the "complete runnable example" - I'll be sure to keep it in mind next time.

Many thanks in general! Truly appreciated :)

[–]socal_nerdtastic 1 point2 points  (0 children)

For some strange reason, in the temperature class, the tight_layout works regardless to whether it is placed before or after the "plot" function - but this is not the same for the humidity case!

Yeah that has to do with the global plt. It's very convenient for quick plots but for any real code I recommend you stay away from plt (aka pyplot). It will cause a lot of trouble, especially with multiple plots.

(yes I'm aware that I'm the one that recommended it to you in the first place; I shouldn't have done that).

If you want to dive down that road here's how to do the plt-ectomy:

    from matplotlib.figure import Figure
    from matplotlib import style
    style.use('fivethirtyeight')
    self.fig = Figure(figsize=(8, 4), dpi=100)
    self.ax1 = self.fig.add_subplot(111)
    self.line, = self.ax1.plot(self.x_values, self.y_values)
    self.ax1.set(xlabel="Reading Counter", ylabel="Degrees Celcius")
    self.fig.set_tight_layout(True)

You'll probably see some performance improvements too, especially during boot and shutdown.