-
-
Notifications
You must be signed in to change notification settings - Fork 7
Save Plot to a file
kojix2 edited this page Jun 18, 2020
·
10 revisions
If you are using GR::Plot
, call savefig
method.
require 'gr/plot'
x = [1, 2, 3, 4, 5]
y = [1, 8, 27, 64, 125]
GR.plot(x, y)
You can specify the format by file name or extension.
png
ps
gif
bmp
jpg
tiff
pdf
svg
GR.savefig('image.png')
You can add keyword values.
GR.savefig('image.png', title: 'PNG')
If you are working with low-level API, use beginprint
and endprint
.
GR.beginprint("image.png")
# plot something nice...
GR.endprint
Note: The format of images and videos that can be generated by GR.rb depends on the library you link.
Use beginprint
and endprint
.
require 'gr/plot'
x = []; y = []; z = []
GR.beginprint("video.gif")
500.times do |i|
z << i / 100.0
x << i**2 * Math.sin(i * Math::PI / 10.0) / 100.0
y << i**2 * Math.cos(i * Math::PI / 10.0) / 100.0
GR.plot3(x, y, z, 'p', title: "i = #{i}")
GR.updatews
sleep 0.005
end
GR.endprint
User's Guide
Simple, matlab-style API
- Plotting functions
- Plot attributes
- Multiple plots
- Multiple subplots
- Save Plot to a file
- Jupyter Notebook
GR Native functions
For developers