From Wikisophia
Jump to: navigation, search

Plot from data

I've been looking everywhere, and I can't find any examples of using WikiTeX/plot to plot data, e.g. a histogram. Gnuplot requires you to keep such data in a datafile that you specify to the "plot" command, but I don't know how I would include such a datafile in WikiTeX. Can you specify another Wiki page? Does it have to be a file available on the server? Thanks, Bovlb 16:11, 11 Oct 2005 (CDT)

  • I believe I've found the answer: This wikitex-l mail suggests that you can download files from the server if you relax a security restriction, but it doesn't say what the working directory is. This Gnuplot FAQ says that you can include data inline with plot "-"; this requires the same security relaxation, of course. Bovlb 16:40, 11 Oct 2005 (CDT)

On further investigation, the inline file is not very useful for histograms. More useful is to be able to include previously-uploaded files directly. Consider the following replacement for strPlot in wikitex.php:

function strPlot($str)
  global $objRend;
		 $str, $out, PREG_PATTERN_ORDER);
  foreach ($out[1] as $title) {
    $image = Image::newFromName($title);
    $path = $image->getImagePath();
    $str = str_replace("[[Image:" . $title . "]]", "\"" . $path . "\"", $str);
    $str .= "# " . $path . " modified " . 
      date("Y-m-d H:i:s", filemtime($path)) . "\n";
  return $objRend->strRend($str, array('class' => 'plot'));

This allows you to say, e.g.:

 plot [[Image:immigration.dat]]

and it gets transformed into something like:

 plot "/var/www/html/wiki/images/a/ac/Immigration.dat" 

Does this seem like the right approach? Bovlb 16:44, 17 Oct 2005 (CDT)

Sigh. My new problem is that, if the datafile is modified, then the caching mechanism prevents any of the plots being updated unless you make a trivial change to the gnuplot commands. I guess the cachefile name is a hash of the contents of the plot tag. If I could only incorporate the timestamp on the datafile ... Bovlb 13:44, 18 Oct 2005 (CDT)

  • Fixed. Code above updated. Bovlb 20:17, 18 Oct 2005 (CDT)
As of 1.1-beta3, you can upload a file or start a wiki page and reference it so:
<plot data="upload">plot "upload" using 1:2;</plot>
Danenberg 01:53, 24 February 2006 (CST)

Colors and interception points

Hi, is it possible to give curves different colors ?

set samples 500
set size 0.5,0.5
set multiplot
set arrow from 0,-9 to 0,9
set arrow from -3,0 to 3,0
plot [-3:3][-10:10] 2*x-1
plot [-3:3][-10:10] -2*x+4

SOLVED! btw: when i try 3d-plotting, i only get an empty plot. (with unset surfaces i only get a red rough sketch) looks like red is the standard color for everything. can i change this? in commandline with gnuplot, everythings fine... SOLVED!

Oh, i nearly forgot: is it possible to mark the interception point of these 2 curves ? -- Lykorn 15:24, 4 Jan 2006 (CST)

Ok Ok :D i got that with the colors