Page 1 of 10

Gnuplot Scripts

PostPosted: Wed May 13, 2015 5:49 pm
by DaveL17
Here are a couple of Gnuplot scripts that I use to generate these graphics:

Screen Shot 2015-05-13 at 2.40.19 PM.png
Screen Shot 2015-05-13 at 2.40.19 PM.png (57.39 KiB) Viewed 10829 times

Each graph has nuances that make it a better deal to use separate Gnuplot scripts to generate each graphic.

24 Hour Forecast:
Code: Select all
#! /usr/bin/env gnuplot
reset

set terminal pngcairo enhanced background "#000000" font "Lato-Light,9" linewidth 1 rounded size 600,200
set output "/Users/......./Dropbox/Public/hourlyForecast.png"
dataFileForecast = "/Users/......./Dropbox/Public/hourlyForecast.csv"
set datafile separator ','
set timefmt "%Y-%m-%d %H:%M"
stats dataFileForecast using 2 nooutput

freezeWarning = 32.
Yhigh = STATS_max + 10.
Ylow = STATS_min - 10.
freezeLabel = ((freezeWarning-Ylow) / (Yhigh-Ylow))

unset key
set border linetype rgb "#666666"
set boxwidth 0.25 relative
set style fill transparent solid 0.4
set style line 1 linetype rgb "#666666"
set style line 2 linetype rgb "#FFFFFF" pointtype 7 pointsize .5
set style line 3 linetype rgb "#0066CC"
set style line 4 linetype rgb "#FFFF00"

unset mxtics
set tics textcolor rgb "#666666"

# X Axis
set xdata time
set xtics format "%l:00 %p" nomirror
set autoscale xfix
set offsets 60*60,60*60,0,0

# Post the label "32°" if it will appear on the graph (based on dynamic Y range)
if (32 > Ylow) set label "32°" at graph 0.01,freezeLabel tc rgb "#FFFFFF" font ",8"

# Y Axis
set ytics format "%2.0f°" nomirror
set yrange [Ylow:Yhigh]
unset ytics

# Y2 Axis
set y2tics format "%2.0f%%" nomirror
set y2range [0:100]

plot dataFileForecast using 1:3 with impulses linestyle 4 axes x1y2,\
     dataFileForecast using 1:2 with filledcurve above y1=0 linestyle 1 axes x1y1,\
     dataFileForecast using 1:2 with points linestyle 2 axes x1y1,\
     dataFileForecast using 1:2:4 with labels offset 0,0.75 textcolor "#FFFFFF" font ",8" axes x1y1,\
     freezeWarning with filledcurve above y1=0 linestyle 3 axes x1y1
     

10 Day Forecast:
Code: Select all
#! /usr/bin/env gnuplot
reset

set terminal pngcairo enhanced background "#000000" font "Lato-Light,9" linewidth 1 rounded size 600,200
set output "/Users/......./Dropbox/Public/10DayForecast.png"
dataFileForecast = "/Users/......../Dropbox/Public/10DayForecast.csv"
set datafile separator ','
set timefmt "%Y-%m-%d"
stats dataFileForecast using 2:4 nooutput

freezeWarning = 32.
Yhigh = STATS_max_x + 10.
Ylow = STATS_min_y - 10.
freezeLabel = ((freezeWarning-Ylow) / (Yhigh-Ylow))

unset key
set border linetype rgb "#666666"
set boxwidth 0.25 relative
set style fill transparent solid 0.4
set style line 1 linetype rgb "#0066CC"
set style line 2 linetype rgb "#FFFFFF" pointtype 7 pointsize .5
set style line 3 linetype rgb "#666666"
set style line 4 linetype rgb "#FFFF00"
set style line 5 linetype rgb "#333333"

set label "°" right

unset mxtics
set tics textcolor rgb "#666666"

# X Axis
set xdata time
set xtics format "%a" nomirror
set autoscale xfix
set offsets 12*60*60,12*60*60,0,0

# Y Axis
set ytics format "%2f°" nomirror
set yrange [Ylow:Yhigh]
unset ytics
if (32 > Ylow) set label "32°" at graph 0.01,freezeLabel tc rgb "#FFFFFF" font ",8"

# Y2 Axis
set y2tics format "%2.0f%%" nomirror
set y2range [0:100]

plot dataFileForecast using 1:6 with impulses linestyle 4 axes x1y2,\
     dataFileForecast using 1:2 with filledcurves above y1=0 linestyle 5 axes x1y1,\
     dataFileForecast using 1:2 with points linestyle 2 axes x1y1,\
     dataFileForecast using 1:2:3 with labels offset 1.75,0.5 textcolor "#FFFFFF" font ",8" axes x1y1,\
     dataFileForecast using 1:4 with filledcurves above y1=0 linestyle 3 axes x1y1,\
     dataFileForecast using 1:4 with points linestyle 2 axes x1y1,\
     dataFileForecast using 1:4:5 with labels offset 1.75,0.5 textcolor "#FFFFFF" font ",8" axes x1y1,\
     freezeWarning with filledcurve above y1=0 linestyle 1 axes x1y1
     

I call both scripts (along with many others) from a Python script which generates new PNG images every 15 minutes. Then, it's a simple matter of plugging them into a control page. If anyone has any questions about script elements, or suggestions for improvements, feel free to post them here. I am by no means a Gnuplot expert, but can explain the elements I use.

Dave

Re: Gnuplot Scripts

PostPosted: Wed May 13, 2015 7:25 pm
by RogueProeliator
Those look awesome, Dave!

Re: Gnuplot Scripts

PostPosted: Wed May 13, 2015 8:22 pm
by DaveL17
That's quite a compliment coming from you. Thanks!
Dave

Re: Gnuplot Scripts

PostPosted: Wed May 13, 2015 11:13 pm
by kw123
that looks perfect to me!!

You might want to consider:
Code: Select all
flabel(y)=sprintf("%.1f", y)
...
using 1: 52 : (flabel($52)) every 2   with labels   offset character 0,character 1.5 tc rgb "blue" title "" axis x1y1\
if you want to control the format of the number thin out the# of numbers.

again.. this is nice!!

Karl

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 4:36 am
by DaveL17
Thanks Karl, I appreciate the kind words.

I saw sprint and gprint in the manual, but haven't tried to use them yet. I'm in control of the format of the number going into the source CSV file (I create them with Python scripts) so no worries there. One thing that I would like to be able to do, though, is to get rid of the leading zero in the time value "04:00" but I haven't been able to find a format specifier to be able to do that. Maybe sprint or gprint is the answer to that too,,,

Dave

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 9:13 am
by ckeyes888
They really do look terrific. Are these at all possible using 10.5.8 - 6.0.20?

Love to try them out.

Thanks,

Carl

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 9:51 am
by DaveL17
Thanks Carl!

There are really no special requirements. These are generated with Gnuplot v5.0.0 outside of Indigo, but using Indigo as the timer for updates, data formatting and generating the images. Every 15 minutes, I run a Python script that takes the needed data from device states, variables, etc., write to a CSV file, and spawn an instance of Gnuplot to generate a PNG file (through an outside call.) Here's a sample of the Python script I run (written very literally at this point.) It's really very simple. Set up a schedule to run every X minutes, with an embedded or linked script that runs the code below (obviously customized to your environment.)

One thing I should explain about the CSV file that I write. I actually write two values for each temperature in this instance. The first is the numeric value that is used for the line plot (i.e., 59). Then I also write another version for the text label (i.e., 59°). That's why you see high temp and low temp twice and precipitation once.

The weather graphics are actually on the control page and not in the Gnuplot graph.

Dave

Code: Select all
#! /usr/bin/env python2.6
# -*- coding: utf-8 -*-

import os.path
from os import system

csvFilePath = "/Users/......./Dropbox/Public/10DayForecast.csv"
dateTime    = str(indigo.server.getTime())

day1       = str(indigo.devices[1124555076].states["d01_date"])
day2       = str(indigo.devices[1124555076].states["d02_date"])
day3       = str(indigo.devices[1124555076].states["d03_date"])
day4       = str(indigo.devices[1124555076].states["d04_date"])
day5       = str(indigo.devices[1124555076].states["d05_date"])
day6       = str(indigo.devices[1124555076].states["d06_date"])
day7       = str(indigo.devices[1124555076].states["d07_date"])
day8       = str(indigo.devices[1124555076].states["d08_date"])
day9       = str(indigo.devices[1124555076].states["d09_date"])
day10       = str(indigo.devices[1124555076].states["d10_date"])
highTemp1       = str(int(indigo.devices[1124555076].states["d01_high"]))
highTemp2       = str(int(indigo.devices[1124555076].states["d02_high"]))
highTemp3       = str(int(indigo.devices[1124555076].states["d03_high"]))
highTemp4       = str(int(indigo.devices[1124555076].states["d04_high"]))
highTemp5       = str(int(indigo.devices[1124555076].states["d05_high"]))
highTemp6       = str(int(indigo.devices[1124555076].states["d06_high"]))
highTemp7       = str(int(indigo.devices[1124555076].states["d07_high"]))
highTemp8       = str(int(indigo.devices[1124555076].states["d08_high"]))
highTemp9       = str(int(indigo.devices[1124555076].states["d09_high"]))
highTemp10       = str(int(indigo.devices[1124555076].states["d10_high"]))
lowTemp1       = str(int(indigo.devices[1124555076].states["d01_low"]))
lowTemp2       = str(int(indigo.devices[1124555076].states["d02_low"]))
lowTemp3       = str(int(indigo.devices[1124555076].states["d03_low"]))
lowTemp4       = str(int(indigo.devices[1124555076].states["d04_low"]))
lowTemp5       = str(int(indigo.devices[1124555076].states["d05_low"]))
lowTemp6       = str(int(indigo.devices[1124555076].states["d06_low"]))
lowTemp7       = str(int(indigo.devices[1124555076].states["d07_low"]))
lowTemp8       = str(int(indigo.devices[1124555076].states["d08_low"]))
lowTemp9       = str(int(indigo.devices[1124555076].states["d09_low"]))
lowTemp10       = str(int(indigo.devices[1124555076].states["d10_low"]))
precip1       = str(indigo.devices[1124555076].states["d01_pop"])
precip2       = str(indigo.devices[1124555076].states["d02_pop"])
precip3       = str(indigo.devices[1124555076].states["d03_pop"])
precip4       = str(indigo.devices[1124555076].states["d04_pop"])
precip5       = str(indigo.devices[1124555076].states["d05_pop"])
precip6       = str(indigo.devices[1124555076].states["d06_pop"])
precip7       = str(indigo.devices[1124555076].states["d07_pop"])
precip8       = str(indigo.devices[1124555076].states["d08_pop"])
precip9       = str(indigo.devices[1124555076].states["d09_pop"])
precip10       = str(indigo.devices[1124555076].states["d10_pop"])

csvFile = open(csvFilePath, "w")
element = (day1 + "," + highTemp1 + "," + highTemp1 + "°," + lowTemp1 + "," + lowTemp1 + "°," + precip1 + "\n" +
         day2 + "," + highTemp2 + "," + highTemp2 + "°," + lowTemp2 + "," + lowTemp2 + "°," + precip2 + "\n" +         
         day3 + "," + highTemp3 + "," + highTemp3 + "°," + lowTemp3 + "," + lowTemp3 + "°," + precip3 + "\n" +
         day4 + "," + highTemp4 + "," + highTemp4 + "°," + lowTemp4 + "," + lowTemp4 + "°," + precip4 + "\n" +
         day5 + "," + highTemp5 + "," + highTemp5 + "°," + lowTemp5 + "," + lowTemp5 + "°," + precip5 + "\n" +
         day6 + "," + highTemp6 + "," + highTemp6 + "°," + lowTemp6 + "," + lowTemp6 + "°," + precip6 + "\n" +
         day7 + "," + highTemp7 + "," + highTemp7 + "°," + lowTemp7 + "," + lowTemp7 + "°," + precip7 + "\n" +
         day8 + "," + highTemp8 + "," + highTemp8 + "°," + lowTemp8 + "," + lowTemp8 + "°," + precip8 + "\n" +
         day9 + "," + highTemp9 + "," + highTemp9 + "°," + lowTemp9 + "," + lowTemp9 + "°," + precip9 + "\n" +
         day10 + "," + highTemp10 + "," + highTemp10 + "°," + lowTemp10 + "," + lowTemp10 + "°," + precip10)

csvFile.write(element)
csvFile.close()

system('/opt/local/bin/gnuplot /Library/Application\ Support/Perceptive\ Automation/Indigo\ 6/Scripts/10DayForecast.gp')

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 10:03 am
by kw123
Try:

%k hour, 0–23 (one or two digits)

instead of:
%H hour, 00–23 (always two digits)

or
%l hour, 1–12 (one or two digits) this is a lower case L
instead of
%I hour, 01–12 (always two digits) this is an upper case i
don't know if it works in gnu 4.x but it does in 5.0


Karl

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 10:17 am
by ckeyes888
Many thanks! Look forward to checking it out.

Carl

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 10:30 am
by DaveL17
kw123 wrote:
Try:

%l hour, 1–12 (one or two digits) this is a lower case L

Karl

Karl! That's exactly what I wanted--I don't think it was available (or at least, wasn't documented in 4.x).

Thank you!
Dave

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 5:55 pm
by ckeyes888
Curious about the forecast.csv file. I assume it's the file the charting info is derived from
but have no idea how it's setup or created.

Any help appreciated!

Edit: Also getting an error trying compile this line in Indigo:

set terminal pngcairo enhanced background "#000000" font "Lato-Light,9" linewidth 1 rounded size 600,200

Says "Invalid syntax"

Thanks,

Carl

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 6:19 pm
by DaveL17
ckeyes888 wrote:
Curious about the forecast.csv file. I assume it's the file the charting info is derived from
but have no idea how it's setup or created.

Any help appreciated!

Thanks,

Carl

Hi Carl - the Python script above generates the CSV file that the chart is based on. The one above generates the CSV for the 10 day forecast, but the principle is the same. The CSV looks like this:

Code: Select all
2015-05-14,67,67°,58,58°,90.0
2015-05-15,81,81°,63,63°,40.0
2015-05-16,82,82°,66,66°,50.0
2015-05-17,82,82°,64,64°,80.0
2015-05-18,72,72°,44,44°,10.0
2015-05-19,56,56°,40,40°,0.0
2015-05-20,62,62°,45,45°,0.0
2015-05-21,67,67°,48,48°,10.0
2015-05-22,72,72°,52,52°,10.0
2015-05-23,74,74°,57,57°,40.0

There are six columns of data that are used by the Gnuplot script. So it's:

Python --> CSV --> Gnuplot.

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 6:30 pm
by ckeyes888
Guess I'm out of my depth here. The script that creates the .csv file needs input from
what appears to be a number of devices. I had assumed it may gather its data from
an online source.

So I need to install something that would create a weather device with all the device states
needed for the csv?

I currently use the NOAA Weather Plus plugin.

Thanks,

Carl

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 7:07 pm
by DaveL17
For this particular purpose you could use any Indigo device that knows the forecast high temperature, forecast low temperature, and chance of precipitation. I highly recommend the WUnderground plugin! :D

But I think the broader point is just to demonstrate how to chart anything you want (within reason) from Indigo.

Screen Shot 2015-05-14 at 8.00.41 PM.png
Screen Shot 2015-05-14 at 8.00.41 PM.png (22.18 KiB) Viewed 10634 times

Screen Shot 2015-05-14 at 8.00.13 PM.png
Screen Shot 2015-05-14 at 8.00.13 PM.png (29.65 KiB) Viewed 10634 times

Screen Shot 2015-05-14 at 7.59.53 PM.png
Screen Shot 2015-05-14 at 7.59.53 PM.png (27.75 KiB) Viewed 10634 times

Re: Gnuplot Scripts

PostPosted: Thu May 14, 2015 7:11 pm
by ckeyes888
Thanks Dave. I'll dive in and see what happens.

Carl