Patches: Browse | Submit New | Admin

[#1583] set origin

Date:
2005-03-06 08:20
Priority:
3
Submitted By:
Kensaku Maki (shakapon)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
set origin

Detailed description
Hi. My name is Kensaku, and I am graduate school student.
Thank you for your rgplot, it is cool. 
But... current rgplot could not use "set origin", because rgplot were separated by setting and dataset. 

To fix this problem, I suggest that we include origin variable for variable class.

Sample Patch as follows.
-----------------------
141,142c141,142
<     attr_accessor :title, :with, :using, :data, :linewidth, :matrix
<
---
>     attr_accessor :title, :with, :using, :data, :linewidth, :matrix, :origin
>
153,156c153,156
<
<       # Order of these is important or gnuplot barfs on 'em
<
<       io << ( (@data.instance_of? String) ? @data : "'-'" )
---
>         if @origin.class  ==Array
>               io<< "\nset origin "+sprintf("%f",@origin[0]) +", "+
sprintf("%f",@origin[1])+"\n"
>         end
>       # Order of these is important or gnuplot barfs on 'em
157a158
>       io <<"plot "<< ( (@data.instance_of? String) ? @data : "'-'" )
168a170
>       io << "\n"
------------------


And, sample code as follows ( this code were extended from your sample code).
-------------------
require '../lib/gnuplot'

# File.open( "gnuplot.dat", "w") do |gp|
Gnuplot.open do |gp|
  Gnuplot::Plot.new( gp,"" ) do |plot|
  
    plot.xrange "[-10:10]"
    plot.title  "Sin Wave Example"
    plot.ylabel "x"
    plot.xlabel "sin(x)"
    plot.size "0.5" # add the this command
    plot.multiplot # insert this command
    
    x = (0..50).collect { |v| v.to_f }
    y = x.collect { |v| v ** 2 }

    plot.data = [
      Gnuplot::DataSet.new( "sin(x)" ) { |ds|
      	ds.origin=[0.0,0.0] # add the this variable
	ds.with = "lines"
	ds.title = "String function"
	ds.linewidth = 4
      },
    
      Gnuplot::DataSet.new( [x, y] ) { |ds|
      	ds.origin=[0.0,0.0] # add the this variable
	ds.with = "linespoints"
	ds.title = "Array data"
     }
    ]

  end
  
end
-------------------    

English is my second language, and this is my first posting.
Please let up on some mistake.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-07-16 13:03
Sender: Roger Pack

if this is still a problem could you file an issue
at http://github.com/rogerdpack/ruby_gnuplot/tree/master ? (though
not the original creator, I'm going to upkeep a maintained branch
there).
Thanks
Date: 2009-07-08 19:51
Sender: Roger Pack

is this resolved then?
Date: 2006-02-08 18:35
Sender: Michael Neilson

after using your patch and wanting 'add' for functionality to
multiplot I discovered that the correct way to use multiplot
in rgplot is as follows

Open Gnuplot
make a plot with x number of DataSets and use multiplot command

then for seperate plots
create a new Gnuplot::Plot  and set it's values

Below is an eample.  Thanks for making this patch. Though
it seems it wasn't needed.


#!/usr/bin/env ruby18

require 'rubygems'
require_gem 'gnuplot'

x = (0..50).collect { |v| v.to_f }
y = x.collect { |v| v**2 }

d1 = Gnuplot::DataSet.new( 'sin(x)' ) do |ds|
        ds.with = 'lines'
        ds.linewidth = 4
     end
d2 = Gnuplot::DataSet.new( [x,y] ) do |ds|
        ds.with = 'lines'
        ds.linewidth = 4
        ds.title = 'y=x^2'
     end

d3 = Gnuplot::DataSet.new( 'sin(x)*cos(x)' ) do |ds|
        ds.with = 'lines'
        ds.linewidth = 2
        ds.title = 'sin(x)*cos(x)'
     end

#Gnuplot::open do |gp|
File::open 'test.dat', 'w' do |gp|
    Gnuplot::Plot.new gp do |plot|
        
        plot.title 'blah'
        plot.multiplot
        plot.data << d1 << d3
    
    
    end
    # multiplot
    Gnuplot::Plot.new gp do |plot|
        plot.origin '0.4, 0.4'
        plot.size   '0.5, 0.5'
        plot.title 'test'
        plot.data << d2
    end

end
Date: 2006-02-07 01:35
Sender: Nobody

Thank you, this patch was very helpful in getting this packages
to be usefull at my work.

Attached Files:

Name Description Download
set_origin.patch Download

Changes:

Field Old Value Date By
File Added175: set_origin.patch2005-03-06 08:20shakapon