|
From: Steve C. <sc...@ja...> - 2009-11-17 01:00:04
|
Duh, answering my own question, this one was in the book (p.230).
This version works. I had been under the mistaken impression that the
"pipe" version of "data files" had to follow the disk version exactly,
but it's actually MORE flexible. You don't have to have all this double
line hackery. "e" should be thought of as standing for "end of data" as
opposed to "end of file" which is how I was thinking of it.
#!/usr/bin/python
import os
import sys
print "Content-Type: image/png" # This is an image
print # blank line, end of headers
sys.stdout.flush()
gp = os.popen("/usr/bin/gnuplot", 'w')
gp.write('reset\n')
gp.write('set xdata time\n')
gp.write('set timefmt "%Y-%m-%d"\n')
gp.write('set format x "%b"\n')
gp.write('set xrange ["2008-11-15":"2009-11-14"]\n')
gp.write('set yrange [0:24]\n')
gp.write('set ylabel "Hours in use per day"\n')
gp.write('set term png size 960,400 x000000 xdfdfdf xffffff xffff00
x0000ff\n')
gp.write('set output "~/test.png"\n')
gp.write('plot "-" u 1:2 ti "Weekday" w impulses, "-" u 1:2 ti
"Weekend" w impulses\n')
gp.write('2009-07-13 0.5799 6\n')
gp.write('2009-07-14 0.2618 3\n')
gp.write('2009-07-15 0.4646 4\n')
gp.write('2009-07-28 0.2069 2\n')
gp.write('2009-08-18 1.1181 11\n')
gp.write('e\n')
gp.write('2009-07-11 0.7243 7\n')
gp.write('2009-08-30 0.1646 4\n')
gp.write('e\n')
gp.close()
Steve Cohen wrote:
> How is it possible to show multiple data series from a script?
>
> The following doesn't work. Only the first series gets plotted
>
>
> #!/usr/bin/python
>
> import os
> import sys
>
> print "Content-Type: image/png" # This is an image
> print # blank line, end of headers
> sys.stdout.flush()
>
> gp = os.popen("/usr/bin/gnuplot", 'w')
> gp.write('reset\n')
> gp.write('set xdata time\n')
> gp.write('set timefmt "%Y-%m-%d"\n')
> gp.write('set format x "%b"\n')
> gp.write('set xrange ["2008-11-15":"2009-11-14"]\n')
> gp.write('set yrange [0:24]\n')
> gp.write('set ylabel "Hours in use per day"\n')
> gp.write('set term png size 960,400 x000000 xdfdfdf xffffff xffff00
> x0000ff\n')
> gp.write('set output "~/test.png"\n')
> gp.write('plot "-" index 0 u 1:2 ti "Weekday" w impulses, "" index 1
> u 1:2 ti "Weekend" w impulses\n')
> gp.write('2009-07-13 0.5799 6\n')
> gp.write('2009-07-14 0.2618 3\n')
> gp.write('2009-07-15 0.4646 4\n')
> gp.write('2009-07-28 0.2069 2\n')
> gp.write('2009-08-18 1.1181 11\n')
> gp.write('\n')
> gp.write('\n')
> gp.write('2009-07-11 0.7243 7\n')
> gp.write('2009-08-30 0.1646 4\n')
> gp.write('e\n')
> gp.close()
>
> The following error message is seen.
>
> gnuplot> plot "-" index 0 u 1:2 ti "Weekday" w impulses, "" index 1
> u 1:2 ti "Weekend" w impulses
>
> ^
> line 10: warning: Skipping data file with no valid points
>
>
> If instead I modify the script to read the same data from a data file
> both sets are plotted:
>
> #!/usr/bin/python
>
> import os
> import sys
>
> print "Content-Type: image/png" # This is an image
> print # blank line, end of headers
> sys.stdout.flush()
>
> gp = os.popen("/usr/bin/gnuplot", 'w')
> gp.write('reset\n')
> gp.write('set xdata time\n')
> gp.write('set timefmt "%Y-%m-%d"\n')
> gp.write('set format x "%b"\n')
> gp.write('set xrange ["2008-11-15":"2009-11-14"]\n')
> gp.write('set yrange [0:24]\n')
> gp.write('set ylabel "Hours in use per day"\n')
> gp.write('set term png size 960,400 x000000 xdfdfdf xffffff xffff00
> x0000ff\n')
> gp.write('set output "~/test.png"\n')
> gp.write('plot "~/script.data" index 0 u 1:2 ti "Weekday" w impulses,
> "" index 1 u 1:2 ti "Weekend" w impulses\n')
> gp.close()
>
>
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Gnuplot-info mailing list
> Gnu...@li...
> https://lists.sourceforge.net/lists/listinfo/gnuplot-info
>
>
|