Gnuplot Scripts

Posted on
Mon May 18, 2015 8:44 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Gnuplot Scripts

My pleasure.

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

[My Plugins] - [My Forums]

Posted on
Sun Jun 28, 2015 8:05 am
SSteve offline
User avatar
Posts: 84
Joined: Sep 12, 2012
Location: Sierra Foothills, California

Re: Gnuplot Scripts

DaveL17 wrote:
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.13 PM.png

Screen Shot 2015-05-14 at 7.59.53 PM.png


Dave, thanks for posting your gnuplot scripts. They've got me well on my way toward implementing temperature history. On these three graphs, is the title and legend text drawn in gnuplot or are they part of the control page?

Posted on
Sun Jun 28, 2015 9:11 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Gnuplot Scripts

Thanks! The titles are Indigo text--easier to manipulate than in Gnuplot.

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

[My Plugins] - [My Forums]

Posted on
Sun Jun 28, 2015 10:49 am
SSteve offline
User avatar
Posts: 84
Joined: Sep 12, 2012
Location: Sierra Foothills, California

Re: Gnuplot Scripts

DaveL17 wrote:
Thanks! The titles are Indigo text--easier to manipulate than in Gnuplot.


Thanks. I've got some title and legend text now. I've haven't used Control Pages yet. Do you use "Refreshing image URL" to update the graph on your control page?

Posted on
Sun Jun 28, 2015 4:23 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Gnuplot Scripts

Do you use "Refreshing image URL" to update the graph on your control page?

I do. I have the Gnuplot images dump to a Dropbox folder--I call them from the control page and refresh them every minute (I have the Gnuplot script generate a new graphic every 15 minutes.)

Dave

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

[My Plugins] - [My Forums]

Posted on
Sun Jun 28, 2015 5:24 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Gnuplot Scripts

some fancy stuff.

put data markers somewhere on the (temperature) line. Here examples for
- dot @4 hours ago
- dot @ now
- dot @ data from current bin to one hour into the future and put current value as text there

Used are timecolumn() and time() functions from GNUplot. It is actually very difficult to get some info on these (hidden) functions.

timecolumn() results in the time value of the current bin in seconds since the millennium in UTC timezone
time(0 results in current time (when GNUplot runs this file) in seconds since the millennium in UTC timezone

with these 2 functions you can select specific data points or move data to other bins forward or backwards in time.
a good application for forward is a forecast of e.g. energy used by end of day or forecasted rain total by end of day etc.

The data format used is
Code: Select all
YYYYmmddHHMM; $2;$3;$4;$5 ..
201506280000; 10;21;35;433
Code: Select all
set datafile separator ";"
set output '/Users/karlwachs/Plots/x.png'   
set terminal png truecolor enhanced  medium  size 850,350 dashlength 0.5      background rgb "#E0E0E0"
set style fill transparent solid 1.0
set xdata time 
set format x "%H:%M"
set timefmt "%Y%m%d%H%M"   
set xrange["201506280000":"201506290000"]
set format y "%.0f"   
set yrange [70:90] 

TZoffset   = -18000 ## time zone offset for dallas = 6 hours
timeNow   = time(0)/300*300  ## round to closest 5 minutes less than now = start of bin when your binning is 5 minutes

set key inside center top horizontal Right noreverse enhanced autotitles nobox
set border linecolor rgb "#A0A000"
set key textcolor rgb "#A0A000"
set title "place dots along the line" textcolor  rgb "#A0A000"
plot '/Users/karlwachs/Documents/INDIGOplotD/data/minute.dat'\
 using 1:((($4)*(1.0)+(0.0)) > (-2000.0) ? (($4)*(1.0)+(0.0)) : 1/0)                                                                              with l lt 6 lw 1 lc rgb "#000000"  t "Temp"    axis x1y1\
  ,'' using (timeNow+TZoffset)         :(timecolumn(1) >= (timeNow+TZoffset )                                                        )?$4:1/0     with p lt 7 lw 4 lc rgb "#FF0000"  t "now" axis x1y1\
  ,'' using (timeNow+TZoffset -4*3600) :(timecolumn(1) >= (timeNow+TZoffset-4*3600) &&  timecolumn(1) < (timeNow+TZoffset+1-4*3600)  )?$4:1/0     with p lt 7 lw 4 lc rgb "#00FF00"  t "4 hours ago" axis x1y1\
  ,'' using (timeNow+TZoffset +1*3600) :(timecolumn(1) >= (timeNow+TZoffset)                                                         )?$4:1/0     with p lt 7 lw 4 lc rgb "#0000FF"  t "moved now to one hour in future" axis x1y1\
  ,'' using (timeNow+TZoffset +1*3600) :(timecolumn(1) >= (timeNow+TZoffset)                                                         )?$4:1/0:(sprintf("Value=%d",$4)) with labels left  font ",10"  tc rgb "#0000FF"  offset char 1,0 not  axis x1y1\
 ,
you will need to adapt the file names etc.



Karl
Attachments
x.png
x.png (7.27 KiB) Viewed 7590 times

Posted on
Sun Jun 28, 2015 9:32 pm
SSteve offline
User avatar
Posts: 84
Joined: Sep 12, 2012
Location: Sierra Foothills, California

Re: Gnuplot Scripts

I can't figure out why I'm not getting fill below the low temperature in this plot. Here's the gnuplot source:

Code: Select all
#!/opt/local/bin/gnuplot
reset

set terminal pngcairo enhanced background "#000000" font "Lato-Light,20" linewidth 1 rounded size 2048,670
set output "/Users/steve/Documents/Temperature History/10DayForecast.png"
dataFileForecast = "/Users/steve/Documents/Temperature History/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.

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" # freeze line
set style line 2 linetype rgb "#FFFFFF" pointtype 7 pointsize .5 # points for both high and low temp
set style line 3 linetype rgb "#000077" # fill for low temp
set style line 4 linetype rgb "#FFFF00" # rain forecast
set style line 5 linetype rgb "#770000" # fill for high temp
set style line 6 linetype rgb "#FF7777" # line for high temp
set style line 7 linetype rgb "#3377FF" # line for low temp

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 yrange [Ylow:Yhigh]
unset ytics
if (32 > Ylow) set ytics 32,1,32 tc rgb "#FFFFFF" font ",18"
set ytics format "%2.0f°" nomirror

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

plot dataFileForecast using 1:6 with impulses linestyle 4 axes x1y2,\
    dataFileForecast using 1:2:4 with filledcurves above linestyle 5 axes x1y1,\
    dataFileForecast using 1:2 with lines linestyle 6 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 ",18" axes x1y1,\
    dataFileForecast using 1:4 with filledcurves above y1=0 linestyle 3 axes x1y1,\
    dataFileForecast using 1:4 with lines linestyle 7 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 ",18" axes x1y1,\
    freezeWarning with filledcurve above y1=0 linestyle 1 axes x1y1
   


Here's the data file:
Code: Select all
2015-06-28,92,92°,66,66°,0.0
2015-06-29,91,91°,71,71°,20.0
2015-06-30,97,97°,74,74°,0.0
2015-07-01,100,100°,74,74°,0.0
2015-07-02,92,92°,71,71°,20.0
2015-07-03,91,91°,70,70°,0.0
2015-07-04,90,90°,70,70°,0.0
2015-07-05,90,90°,68,68°,0.0
2015-07-06,89,89°,67,67°,0.0
2015-07-07,89,89°,66,66°,0.0


Here's the result:
10DayForecast.png
10DayForecast.png (27.55 KiB) Viewed 7421 times


I've looked at other examples on this thread and the line "dataFileForecast using 1:4 with filledcurves above y1=0 linestyle 3 axes x1y1,\" sure looks right. Why is it not filled blue under the low temperature line? If one of you other gnuplot users can try this out and let me know what happens for you, I'd appreciate it.

I'm using gnuplot 5 if that matters.
Last edited by SSteve on Tue Jun 30, 2015 9:12 am, edited 1 time in total.

Posted on
Sun Jun 28, 2015 9:49 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Gnuplot Scripts

for

dataFileForecast using 1:4 with filledcurves above y1=0 linestyle 3 axes x1y1,\

try:

dataFileForecast using 1:4 with filledcurves above y1=Ylow linestyle 3 axes x1y1,\

or
dataFileForecast using 1:4 with filledcurves above Ylow linestyle 3 axes x1y1,\


sometimes if one boundary is outside the plot range it does wrong things..


karl

Posted on
Sun Jun 28, 2015 9:52 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Gnuplot Scripts

also I would not use "," as data separator, sometimes if you do non US , is the . and then there is the thousand separator .. I have found that ";" always works.

Posted on
Mon Jun 29, 2015 5:48 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Gnuplot Scripts

Hard to read the code in Tapatalk, but have a look at the second plot line.

You have "with filledcurves above" but it looks like you don't say above what. Try adding Y1=0 to that line.

Dave

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

[My Plugins] - [My Forums]

Posted on
Mon Jun 29, 2015 7:39 am
SSteve offline
User avatar
Posts: 84
Joined: Sep 12, 2012
Location: Sierra Foothills, California

Re: Gnuplot Scripts

DaveL17 wrote:
Hard to read the code in Tapatalk, but have a look at the second plot line.

You have "with filledcurves above" but it looks like you don't say above what. Try adding Y1=0 to that line.

Dave


That line works. It's the one that draws the red between series 2 and series 4. Since there are two Y series in that line, "above" means "above the second series." It could also specify a second "below" color which would be used between the two series in areas where the first series goes below the second.

Also, sorry to everyone for the huge image. I'm more used to forum software that automatically scales images down to a reasonable size. I'll try to edit that post to use a smaller image after work tonight.

Posted on
Mon Jun 29, 2015 9:01 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Gnuplot Scripts

See if you can fill all the way to the axis for both lines. There may be a chance that Gnuplot is choking on the "stacked" nature of the chart you're trying to build. My fills all go to the axis for all lines--but appear stacked because each fill is written on top of the last.

Dave

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

[My Plugins] - [My Forums]

Posted on
Mon Jun 29, 2015 9:27 pm
SSteve offline
User avatar
Posts: 84
Joined: Sep 12, 2012
Location: Sierra Foothills, California

Re: Gnuplot Scripts

DaveL17 wrote:
See if you can fill all the way to the axis for both lines. There may be a chance that Gnuplot is choking on the "stacked" nature of the chart you're trying to build. My fills all go to the axis for all lines--but appear stacked because each fill is written on top of the last.

Dave


Which version of gnuplot are you running? I started from the code from your original post in this thread which looks like it works for you. I asked over at Stack Overflow (http://stackoverflow.com/questions/31120767/cant-get-gnuplot-to-fill-below-line) and it seems like this might be a bug in 5.0. The person who answered the question had a workaround that is working fine. It creates a series with a value of zero and fills down to that:

Code: Select all
dataFileForecast using 1:4:(0) with filledcurves linestyle 3

Posted on
Tue Jun 30, 2015 3:46 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Gnuplot Scripts

Which version of gnuplot are you running?

Code: Select all
   G N U P L O T
   Version 5.0 patchlevel 0    last modified 2015-01-01

Although they look like it, my fills aren't stacked (all of the fills are to the X axis.) The light gray fill is just covering the dark gray fill behind it.

10DayForecast.png
10DayForecast.png (15.36 KiB) Viewed 7452 times

Dave

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

[My Plugins] - [My Forums]

Posted on
Tue Jun 30, 2015 7:20 am
SSteve offline
User avatar
Posts: 84
Joined: Sep 12, 2012
Location: Sierra Foothills, California

Re: Gnuplot Scripts

DaveL17 wrote:
Which version of gnuplot are you running?

Code: Select all
   G N U  :( P L O T
   Version 5.0 patchlevel 0    last modified 2015-01-01

Although they look like it, my fills aren't stacked (all of the fills are to the X axis.) The light gray fill is just covering the dark gray fill behind it.
Dave


Mine is patchlevel 1. I'm only using stacked fills because when I try to fill to the X axis, I get nothing. Can you try my code above and see what you get? I think it's effectively the same as your code with a couple color tweaks. I'm using your format for the CSV file.

edit:
Never mind. It's definitely a bug and has been fixed in 5.0.1. From the release notes (http://gnuplot.info/ReleaseNotes_5_0_1.html): "FIX breakage in plot style filledcurves {above|below} y1=<yval>". I wish I knew that before spending a few hours (and wasting your time) trying to figure out what I was doing wrong. :(

Page 5 of 10 1, 2, 3, 4, 5, 6, 7, 8 ... 10

Who is online

Users browsing this forum: No registered users and 1 guest