This repository was archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Example
Alish Dipani edited this page Sep 11, 2018
·
2 revisions
require_relative '../../lib/grruby'
x1 = [1, 2, 3, 4, 5]
y1 = [10, 20, 30, 40, 50]
x2 = [2, 4, 16]
y2 = [10, 20, -40]
values = [0, 24, -12, 48]
a = Rubyplot::Figure.new
a.subplot!(2, 2, 1)
a.line! x1, y1, marker_size: 1
a.scatter! x2, y2
a.subplot!(2, 2, 2)
a.bar! values, bar_color: :orange, bar_gap: 1
a.subplot!(2, 1, 2)
a.clear!
a.scatter! x2, y2
a.view
a.clear_figure!
a.line! x1, y1, line_color: :red, line_type: :dashed
a.viewCode is present in : GRRruby-extension/examples/Wiki_example.rb
require_relative '../../lib/grruby' #Including the library#Defining the data
x1 = [1, 2, 3, 4, 5]
y1 = [10, 20, 30, 40, 50]
x2 = [2, 4, 16]
y2 = [10, 20, -40]
values = [0, 24, -12, 48]a = Rubyplot::Figure.new # Initializing new Figure Object aa.subplot!(2, 2, 1) # Initializing a new subplot, the figure is divided
# into 2 rows and 2 columns and index 1 is chosen as the active subplot
# and this active subplot is pushed to the subplot list.a.line! x1, y1, marker_size: 1 # Tasks for line plot is pushed into the
# task list of subplot(2,2,1)a.scatter! x2, y2 # Tasks for scatter plot is pushed into the task
# list of subplot(2,2,1)a.subplot!(2, 2, 2) # Initializing a new subplot, the figure is divided
# into 2 rows and 2 columns and index 2 is chosen as the active subplot
# and this active subplot is pushed to the subplot lista.bar! values, bar_color: :orange, bar_gap: 1 # Tasks for bar plot are
# instantiated and directly called because it is inherited from Lazy
# base i.e. it is a lazy plota.subplot!(2, 1, 2) # Initializing a new subplot, the figure is divided
# into 2 rows and 1 column and index 2 is chosen as the active subplot
# and this active subplot is pushed to the subplot lista.clear! # calls the clear function of the subplot(2,1,2) object and
# clears the task list of the object
# Here, since the subplot object is initialized just before clear,
# it has no effect as the task list is emptya.scatter! x2, y2 # Tasks for scatter plot is pushed into the task
# list of subplot(2,1,2)a.view # view function of plotspace is called, the state of figure is
# copied to the plotsapce object and it starts calling tasks from the
# task list of every subplot from subplot list. After calling all
# tasks it views the figurea.clear_figure! # Figure is cleareda.line! x1, y1, line_color: :red, line_type: :dashed # Since, now the figure
# has no subplots defined, this plot is treated as a subplot with identity(1,1,1)
# which is default when no subplots are defined. This subplot is pushed into the
# subplot list and the tasks of line plot are pushed into the task list.a.view # view function of plotspace is called, the state of figure is copied
# to the plotsapce object and it starts calling tasks from the task list of
# every subplot from subplot list. After calling all tasks it views the figure









