Plotting Octave
Plotting Octave
Octave Tutorial #4
Types of Graphs Supported
• X-Y plots
• Scatter plots
• Histogram’s
• Contour
• Polar plots
• Pie Charts
• 3D Meshes
• Many more.
X-Y Plots
• Simple x-y plot y in relation to x
• plot(y) – Plots the vector y with the index as x.
• plot(x,y) – Plots vector y in relation to x vector.
• plot(x,y, fmt) – modifies how the line/points are
drawn. Default is ‘-’ solid line.
• There is also a property, value arguments that can
be used to change certain attributes. Check the
wiki! If you need to use this.
Scatter
• Much like the x-y plot how ever only the points
will be drawn.
• scatter(x,y) – Plots vector y in relation to x
vector.
• scatter(x,y,s) – modifies how big the markers
size is. Default is 8 points.
• You can add the optional argument “filled” to fill
in the markers.
Histogram’s
• Histogram’s are a graph of a count of items in a
matrix or a vector.
• hist(y) – Creates a histogram of the data with 10
bins.
• hist(y, nbins) – Creates a histogram of the data
with nbins number of bins.
Contour
• Contour’s are a cross section of a 3 dimensional
graph parallel to the x,y plane.
• contour(z) – Takes a matrix and makes a contour
of that matrix.
• contour(x,y,z) – if the x & y are the same as used
to make z, the graph will be the same.
Polar plot
• You can also plot data in polar coordinates.
• polar(theta, rho) – draws a polar graph with
each angle theta relating to value rho.
• Fun for drawing circles and spirals.
Pie Charts
• Creates a simple pie chart with a single vector
with each slice being the percentage of the
vector sum.
• pie(x) – creates pie chart of vector x
• pie(x, explode) – creates a pie chart with
optional input explode is a vector of the same
length as x that, if non-zero, "explodes" the slice
from the pie chart.
3D Meshes
• You can draw graphs in 3D space.
• mesh(x,y,z) – Draws a wireframe mesh.
• meshc(x,y,z) – Draws a wireframe mesh with
underlying contour lines.
• meshz(x,y,z) – Draws a wireframe mesh with Z
curtain.
• surf(x,y,z) – Draws a shaded mesh.
Saving Graphs
• You can save graphs as files or even directly
send them to your printer!(Though I
recommend saving to file first)
• print -dpng ‘<filename>.png’
print -djpg ‘<filename>.jpg’
Graph options
• I spoke a little about graph option when talking
about x-y plots. But some more detail:
• Format options: linestyles(‘-’ ‘--’ ‘:’ ‘-.’)
markerstyles(‘+’ ‘o’ ‘*’ ‘.’ ‘x’ ‘s’ ‘d’)
colors(‘k’ ‘r’ ‘g’ ‘b’ ‘m’ ‘c’ ‘w’)
• Attributes: "linestyle", "linewidth", "color", "marker",
"markersize", "markeredgecolor", "markerfacecolor"
Extra’s
• The Octave documents has almost everything you
could need to figure out how to use a graph. Even
some basic examples! (link in description)
• If you don’t get any errors when trying to draw a graph,
use the ‘hold on’ command to refresh the gnuplot
window.
• Using hold on you can plot multiple graphs on the one
image.
• Remember to use ‘close’ to close the graphics window.
Next
• Control Statements