Line Style question?

Posted on
Sat Feb 25, 2017 9:15 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Line Style question?

First off: this is a great plugin - thanks for your efforts Dave, it's much appreciated. :D

I am trying to create a graph to monitor the temperature and setpoint for a room.

Is there a way to plot a line so that it gives a right angle rather than sloped lines.

I am OK with the temperature being shown as joined lines but the heat setpoint would be better shown as rectangular.

So if I have the following CSV data (example):
Code: Select all
Time        Temp      Setpoint
18:00      18.0        6
18:10      18.0        6
18:20      17.9       28
18:30      18.1       28
18:40      18.7       28
18:50      19.5        6
19:00      19.7        6
19:10      18.5        6
Then I would like the setpoint line to track horizontally along the 6 deg C Y-axis and then at 18:20 go vertically to 28 and then track horizontally along the 28 deg C Y-axis until 18:50 where it would descend to 6 deg C and then track horizontally along the 6 deg C Y-axis (if that all makes sense) - so you end up with rectangular shapes. So all changes are done in the vertical.

In the mean while the Temp line would track by joining the dots i.e. as it does at the moment.

Is this possible?

Posted on
Sat Feb 25, 2017 1:10 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Line Style question?

Thanks Jon - that's high praise coming from you. Appreciated!

If I understand, you want something like this:

fig_1.png
fig_1.png (21.35 KiB) Viewed 3752 times

I think it should be doable. It requires the data to to be shifted slightly (note that my y2 values are different than yours).

Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

x_values = ['18:00', '18:10', '18:20', '18:30', '18:40', '18:50', '19:00', '19:10']
y1_values = [18.0, 18.0, 17.9, 18.1, 18.7, 19.5, 19.7, 18.5]
y2_values = [6, 6, 6, 28, 28, 28, 6, 6]

fig, ax = plt.subplots()
final_x_values = [dt.datetime.strptime(x, "%H:%M") for x in x_values]
ax.plot(final_x_values, y1_values)
ax.step(final_x_values, y2_values)
timeFmt = mdates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(timeFmt)

plt.show()

I've had the idea of adding a step option in the back of my mind; I'll move it to the front. :D

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Feb 25, 2017 2:32 pm
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Line Style question?

Hi Dave,
Yes that is it exactly :)

Posted on
Sat Feb 25, 2017 2:51 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Line Style question?

Cool -- I'll make some effort and see what I can gin up.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Feb 25, 2017 4:43 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Line Style question?

Seems matplotlib already thought of the need to shift the observations with 'steps-post' which will eliminate the need to modify the data before plotting it.

Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

x_values = ['18:00', '18:10', '18:20', '18:30', '18:40', '18:50', '19:00', '19:10']
y1_values = [18.0, 18.0, 17.9, 18.1, 18.7, 19.5, 19.7, 18.5]
y2_values = [6, 6, 28, 28, 28, 6, 6, 6]

fig, ax = plt.subplots()
final_x_values = [dt.datetime.strptime(x, "%H:%M") for x in x_values]
ax.plot(final_x_values, y1_values)
ax.plot(final_x_values, y2_values, ls='steps-post')
yearsFmt = mdates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(yearsFmt)

plt.show()

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Feb 25, 2017 5:20 pm
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Line Style question?

Hi Dave,
Excellent - thanks for looking into it. :)

Posted on
Sun Feb 26, 2017 1:37 pm
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Line Style question?

Hi Dave,
Image as requested. :)
matplotlib_StudyMotion.png
matplotlib_StudyMotion.png (12.68 KiB) Viewed 3609 times


In case it helps, the csv data:
Code: Select all
"2017-02-26 15:08:55.459161","1"
"2017-02-26 15:29:41.349360","1"
"2017-02-26 15:36:13.326643","0"
"2017-02-26 15:37:07.342293","0"
"2017-02-26 15:42:05.359670","0"
"2017-02-26 15:44:59.337613","1"
"2017-02-26 15:53:17.320798","1"
"2017-02-26 15:56:17.324108","1"
"2017-02-26 16:01:15.310976","1"
"2017-02-26 16:25:54.287945","1"
"2017-02-26 16:29:39.020370","1"
"2017-02-26 16:30:36.468232","1"
"2017-02-26 16:31:46.317357","1"
"2017-02-26 16:32:02.290467","1"
"2017-02-26 16:46:43.288328","0"
"2017-02-26 18:30:39.169850","1"
"2017-02-26 18:43:36.176026","1"
"2017-02-26 18:43:38.153418","1"
"2017-02-26 18:51:38.997011","1"
"2017-02-26 18:55:00.104274","1"
"2017-02-26 19:00:00.105917","0"
"2017-02-26 19:05:00.100504","0"
"2017-02-26 19:10:00.100116","0"
"2017-02-26 19:15:00.103663","0"
"2017-02-26 19:20:00.084704","0"
"2017-02-26 19:25:00.082249","0"
"2017-02-26 19:30:00.076642","1"
"2017-02-26 19:35:00.071042","1"

Posted on
Sun Feb 26, 2017 3:33 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Line Style question?

Thanks Jon - that's what I thought. Looks like the fill is being applied as a typical line plot. I'll see what I can do about that.

Cheers,
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Feb 26, 2017 4:18 pm
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Line Style question?

Hi Dave,
Many thanks. :)

Posted on
Sun Feb 26, 2017 9:09 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Line Style question?

After a fair bit of research it doesn't appear to really be possible to fill a stepped plot under the versions of matplotlib that Apple has shipped. @Autolog - I'm going to PM you some code to show a demonstration of why this may not be something to include in the plugin... :D

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Feb 27, 2017 10:28 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Line Style question?

Thought I would share an image of a temperature graph:
matplotlib_MasterBedroomTemperature.png
matplotlib_MasterBedroomTemperature.png (22.33 KiB) Viewed 3524 times


The green line represents the setpoint of the radiator thermostat (a Popp TRV which is at low level, at the bottom of the radiator near the floor).
The red line represents the temperature that is recorded by the POPP TRV.
The yellow line is a wall mounted thermostat which is controlling the setpoint of the the POPP TRV via my Stella-Z plugin (which also determines the heating schedule).
The violet line represents the outside temperature.

It's really great being able to visualise the values and see what effect the settings have. :)

I used to use FHEM before migrating to Indigo and that had an inbuilt graphing facility. This plugin plugs the gap (so to speak) and enables me to have similar functionality to that which I had with FHEM. :D

Posted on
Mon Feb 27, 2017 12:35 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Line Style question?

That's awesome. Thanks for sharing your work. That will surely give others some ideas on how they can use the plugin.

Special shout out to Jon for helping me with some great ideas for the plugin, and helping test enhancements. :D

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests