Gnuplot установка данных с ошибками

Plotting points on top of an existing image

This can be done with :

or with :

The invocation is a convenience wrapper for the version. Finer control is available with .

Here an existing image is given to gnuplot verbatim, and data to plot on top of it is interpreted by feedgnuplot as usual. is useful here because usually the y axis points up, but when looking at images, this is usually reversed: the origin is the top-left pixel.

LICENSE AND COPYRIGHT

Copyright 2011-2012 Dima Kogan.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

Data formats

By default, each value present in the incoming data represents a distinct data point, as demonstrated in the original example above (we had 10 numbers in the input and 10 points in the plot). If requested, the script supports more sophisticated interpretation of input data

Domain selection

If is passed in, the first value on each line of input is interpreted as the X-value for the rest of the data on that line. Without the X-value is the line number, and the first value on a line is a plain data point like the others. Default is . Thus the original example above produces 2 curves, with 1,2,3,4,5 as the X-values. If we run the same command with :

we get only 1 curve, with 2,4,6,8,10 as the X-values. As many points as desired can appear on a single line, but all points on a line are associated with the X-value at the start of that line.

Curve indexing

We index the curves in one of 3 ways: sequentially, explicitly with a or by headers.

By default, each column represents a separate curve. The first column (after any domain) is curve . The next one is curve and so on. This is fine unless sparse data is to be plotted. With the option, each point is represented by 2 values: a string identifying the curve, and the value itself. If we add to the original example:

we get 5 different curves with one point in each. The first column, as produced by , is 2,4,6,8,10. These are interpreted as the IDs of the curves to be plotted.

If we’re plotting data (https://www.github.com/dkogan/vnlog) then we can get the curve IDs from the vnlog header. Vnlog is a trivial data format where lines starting with are comments and the first comment contains column labels. If we have such data, can interpret these column labels if the perl modules are available.

The option adds a legend using the given IDs to label the curves. The IDs need not be numbers; generic strings are accepted. As many points as desired can appear on a single line. can be used in conjunction with or .

Multi-value style support

Depending on how gnuplot is plotting the data, more than one value may be needed to represent the range of a single point. Basic 2D plots have 2 numbers representing each point: 1 domain and 1 range. But if plotting with , for instance, then there’s an extra range value: the radius. Many other gnuplot styles require more data: errorbars, variable colors (), variable sizes (), labels and so on. The feedgnuplot tool itself does not know about all these intricacies, but they can still be used, by specifying the specific style with , and specifying how many values are needed for each point with any of , , , . These options are required only for styles not explicitly supported by feedgnuplot; supported styles do the right thing automatically.

Specific example: if making a 2d plot of y error bars, the exact format can be queried by running and invoking . This tells us that there’s a 3-column form: and a 4-column form: . With 2d plots feedgnuplot will always output the 1-value domain , so the rangesize is 2 and 3 respectively. Thus the following are equivalent:

3D data

To plot 3D data, pass in . MUST be given when plotting 3D data to avoid domain ambiguity. If 3D data is being plotted, there are by definition 2 domain values instead of one (Z as a function of X and Y instead of Y as a function of X). Thus the first 2 values on each line are interpreted as the domain instead of just 1. The rest of the processing happens the same way as before.

Time/date data

If the input data domain is a time/date, this can be interpreted with . This option takes a single argument: the format to use to parse the data. The format is documented in ‘set timefmt’ in gnuplot, although the common flags that understands are generally supported. The backslash sequences in the format are not supported, so if you want a tab, put in a tab instead of \t. Whitespace in the format is supported. When this flag is given, some other options act a little bit differently:

  • is an integer in seconds

  • and must use the format passed in to

Using this option changes both the way the input is parsed and the way the x-axis tics are labelled. Gnuplot tries to be intelligent in this labelling, but it doesn’t always do what the user wants. The labelling can be controlled with the gnuplot command, which takes the same type of format string as . Example:

This plots the ‘idle’ CPU consumption against time.

Note that while gnuplot supports the time/date on any axis, feedgnuplot currently supports it only as the x-axis domain. This may change in the future.

Real-time streaming data

To plot real-time data, pass in the option. Data will then be plotted as it is received. The plot will be updated every seconds. If the period isn’t specified, a 1Hz refresh rate is used. To refresh at specific intervals indicated by the data, set the refreshperiod to 0 or to ‘trigger’. The plot will then only be refreshed when a data line ‘replot’ is received. This ‘replot’ command works in both triggered and timed modes, but in triggered mode, it’s the only way to replot. Look in for more information.

To plot only the most recent data (instead of all the data), can be given. This will create an constantly-updating, scrolling view of the recent past. should be replaced by the desired length of the domain window to plot, in domain units (passed-in values if or line numbers otherwise). If the domain is a time/date via , then is and integer in seconds. If we’re plotting a histogram, then causes a histogram over a moving window to be computed. The subtlely here is that with a histogram you don’t actually see the domain since only the range is analyzed. But the domain is still there, and can be utilized with . With we can plot only histograms or only non-histograms.

Special data commands

If we are reading streaming data, the input stream can contain special commands in addition to the raw data. Feedgnuplot looks for these at the start of every input line. If a command is detected, the rest of the line is discarded. These commands are

This command refreshes the plot right now, instead of waiting for the next refresh time indicated by the timer. This command works in addition to the timed refresh, as indicated by .

This command clears out the current data in the plot. The plotting process continues, however, to any data following the .

This command causes feedgnuplot to exit.

Examples

Simple sin wave

Gnuplot.open do |gp|
  Gnuplot::Plot.new( gp ) do |plot|
  
    plot.xrange ""
    plot.title  "Sin Wave Example"
    plot.xlabel "x"
    plot.ylabel "sin(x)"
    
    plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds|
      ds.with = "lines"
      ds.linewidth = 4
    end
    
  end
  
end

Or you can write it out to a file (the above snippet displays the graph, in Linux, but in windows you’d need to write it to a file).

See the file .

Plotting discrete points

Array data can be plotted quite easily since @Array@s have a defined method.

Simply pass an array of data to the constructor of the object or set the data property of the . In this example, because there are two arrays, each array will be a single column of data to the gnuplot process.

Gnuplot.open do |gp|
  Gnuplot::Plot.new( gp ) do |plot|
  
    plot.title  "Array Plot Example"
    plot.xlabel "x"
    plot.ylabel "x^2"
    
    x = (0..50).collect { |v| v.to_f }
    y = x.collect { |v| v ** 2 }

    plot.data << Gnuplot::DataSet.new(  ) do |ds|
      ds.with = "linespoints"
      ds.notitle
    end
  end
end

Multiple Data Sets

As many data sets as are desired can be attached to a plot. Each of these can have their own plot modifiers. Notice in this example how the data array is explicitly set instead of using the operator.

Also in this example, the commands are not written to the Gnuplot process but are instead written to a File called . This file can later be run directly by a gnuplot process as it contains only the gnuplot commands.

File.open( "gnuplot.dat", "w") do |gp|
  Gnuplot::Plot.new( gp ) do |plot|
  
    plot.xrange ""
    plot.title  "Sin Wave Example"
    plot.ylabel "x"
    plot.xlabel "sin(x)"
    
    x = (0..50).collect { |v| v.to_f }
    y = x.collect { |v| v ** 2 }

    plot.data =  ) { |ds|
        ds.with = "linespoints"
        ds.title = "Array data"
      }
    ]

  end
end

Miscellanrous

You can also add arbitrary lines to the output

plot.arbitrary_lines << "set ylabel \"y label\" font \"Helvetica,20\""

Security

Note that if you pass any user-controlled strings to the gem, it’s possible for an attacker to run arbitrary commands.

In addition to title, any other graph properties that accept strings should be affected too. they’re all passed to the system command. So only use strings you trust.

Пыль веков

  • ► 

    (4)

    ► 

    июля
    (1)

    ► 

    июня
    (1)

    ► 

    февраля
    (1)

    ► 

    января
    (1)

  • ► 

    (22)

    ► 

    декабря
    (1)

    ► 

    ноября
    (1)

    ► 

    октября
    (2)

    ► 

    сентября
    (2)

    ► 

    августа
    (1)

    ► 

    июля
    (1)

    ► 

    июня
    (2)

    ► 

    мая
    (2)

    ► 

    апреля
    (3)

    ► 

    марта
    (3)

    ► 

    февраля
    (2)

    ► 

    января
    (2)

  • ► 

    (29)

    ► 

    декабря
    (3)

    • ► 

      ноября
      (2)

    ► 

    октября
    (2)

    ► 

    сентября
    (2)

    ► 

    августа
    (4)

    ► 

    июля
    (3)

    ► 

    июня
    (2)

    ► 

    мая
    (2)

    ► 

    апреля
    (2)

    ► 

    марта
    (2)

    ► 

    февраля
    (2)

    ► 

    января
    (3)

  • ► 

    (27)

    ► 

    декабря
    (2)

    ► 

    ноября
    (3)

    ► 

    октября
    (2)

    ► 

    сентября
    (2)

    ► 

    августа
    (2)

    ► 

    июля
    (2)

    ► 

    июня
    (2)

    ► 

    мая
    (2)

    ► 

    апреля
    (3)

    ► 

    марта
    (3)

    ► 

    февраля
    (2)

    ► 

    января
    (2)

  • ► 

    (31)

    ► 

    декабря
    (3)

    ► 

    ноября
    (2)

    ► 

    октября
    (3)

    ► 

    сентября
    (3)

    ► 

    августа
    (4)

    ► 

    июля
    (3)

    ► 

    июня
    (2)

    ► 

    мая
    (2)

    ► 

    апреля
    (3)

    ► 

    марта
    (2)

    ► 

    февраля
    (2)

    ► 

    января
    (2)

  • ► 

    (35)

    ► 

    декабря
    (2)

    ► 

    ноября
    (3)

    ► 

    октября
    (2)

    ► 

    сентября
    (3)

    ► 

    августа
    (3)

    ► 

    июля
    (2)

    ► 

    июня
    (3)

    ► 

    мая
    (3)

    ► 

    апреля
    (5)

    ► 

    марта
    (4)

    ► 

    февраля
    (2)

    ► 

    января
    (3)

  • ► 

    (64)

    ► 

    декабря
    (6)

    ► 

    ноября
    (4)

    ► 

    октября
    (3)

    ► 

    сентября
    (4)

    ► 

    августа
    (5)

    ► 

    июля
    (6)

    ► 

    июня
    (7)

    ► 

    мая
    (7)

    ► 

    апреля
    (6)

    ► 

    марта
    (6)

    ► 

    февраля
    (4)

    ► 

    января
    (6)

  • ► 

    (91)

    ► 

    декабря
    (7)

    ► 

    ноября
    (7)

    ► 

    октября
    (5)

    ► 

    сентября
    (11)

    ► 

    августа
    (5)

    ► 

    июля
    (8)

    ► 

    июня
    (11)

    ► 

    мая
    (6)

    ► 

    апреля
    (6)

    ► 

    марта
    (5)

    ► 

    февраля
    (12)

    ► 

    января
    (8)

  • ► 

    (59)

    ► 

    декабря
    (10)

    ► 

    ноября
    (9)

    ► 

    октября
    (9)

    ► 

    сентября
    (9)

    ► 

    августа
    (13)

    ► 

    июля
    (9)

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Adblock
detector