Drawing plots
The function draw
executes the instructions that create the graphical visualization of a plot and its components. That function has specialized methods for the different types that have been described in the Structure of plots. In a top-down order:
draw(::Figure)
sets up the workspace and calls thedraw
method for all thePlotObject
s contained inplots
.draw(::PlotObject)
does the following actions:- Paint the background and set the viewport defined by the
viewport
field. - Call the method
draw
on the plot'saxes
. - Call the method
draw
on each item ofgeoms
. - Call
draw
onlegend
it is not an empty legend andattributes[:location] ≠ 0
. - Call
draw
oncolorbar
if it is not an empty color bar andattributes[:colorbar] == true
). - Write different labels and decorations in axes, title, etc, as defined in
attributes
.
- Paint the background and set the viewport defined by the
draw(::Axes)
sets the window and the scale defined by the axes ranges and other specifications — except in the case of polar plots, where the polar coordinates are transformed into the Cartesian coordinates of a square of fixed size, and then draws the axes themselves and their guides.draw(::Geometry)
calls specialized methods for the geometry'skind
, and returns eithernothing
or aVector{Float64}
with the limits of the color scale — when it is calculated by the drawing operation, e.g. in the case of hexagonal bins.- Legends are drawn by the method
draw(lg::Legend, geoms, location)
, wheregeoms
is a vector with the geometries of the plot, andlocation
is an integer code that defines the location of the legend with respect to the main plot area — as defined in Matplotlib legends. The geometries are passed down to theguide
function, which has specialized methods for the kind of geometries that can be represented in legends. - Color bars are drawn by the method
draw(cb::Colorbar [, range])
, where the optionalrange
is by defaultcb.range
, but can be overriden by other values.
The draw
method can be used on a Figure
to trigger its graphical representation, but in most situations it is not necessary to call it explicitly. It is called automatically whenever a figure is meant to be shown in an environment that support SVG, PNG or HTML outputs, such as IJulia notebooks, web-content generators like Weave or Documenter, etc. And there is also a display
method that dispatches on Figure
, whose main action is calling the corresponding draw
method, to display figures in rich multimedia devices.
Thus, one way or another, figures are usually drawn automatically by just invoking them, e.g. if in the last line of a code block you write gcf()
, the name of a variable containing a figure, or if you call a function like plot
that returns a Figure
.