Control operations

Control operations

GRUtils.FigureMethod.
Figure([figsize::Tuple{Float64, Float64}, units::String])

Create a new figure of a given size.

The figure size is defined by figsize (a 2-tuple with the target width and height), and units (a string with the abbreviation of the units: "px" for pixels, "in" for inches, "cm" for centimeters or "m" for meters). The default dimensions used by Figure() with no arguments is 600×450 pixels — or a proportional increased size, if the detected display resolution is high. This constructor also sets the "current figure" to the one that has just been created..

source
GRUtils.gcfFunction.
gcf()
gcf(fig::Figure)

Get the global current figure, or set it to be fig.

source
GRUtils.currentplotFunction.
currentplot([fig::Figure])

Get the "current plot", i.e. the target of the next plotting operations in the (optionally) given figure fig.

If no figure is given, the "current figure" is used (cf. gcf).

source
GRUtils.subplotFunction.
subplot(num_rows, num_columns, indices[, replace])

Set a subplot in the current figure.

By default, the current plot covers the whole window. To display more than one plot, the window can be split into a number of rows and columns, with each plot covering one or more cells in the resulting grid.

Subplot indices are one-based and start at the upper left corner, with a new row starting after every num_cols subplots.

The arguments num_rows and num_cols indicate the number of rows and columns of the grid of plots into which the figure is meant to be divided, and indices is an integer or an array of integers that identify a group of cells in that grid. This function returns a plot with the minimum size that spans over all those cells, and appends it to the array of plots of the figure, such that it becomes its current plot.

If the viewport of the new subplot coincides with the viewport of an existing plot, by default the older one is moved to the first plane, and taken as the "current plot"; but if there is only a partial overlap between the new subplot and other plots, the overlapping plots are removed. To override this behavior and keep all previous plots without changes, set the optional argument replace to false.

Examples

# Create example data
x = randn(100_000)
y = randn(100_000)
# Draw an hexagonal plot in the bigger bottom-right region
subplot(3, 3, (5, 9))
hexbin(x, y, colorbar = false)
# Draw marginal histograms
subplot(3, 3, (2, 3))
histogram(x)
subplot(3, 3, (4, 7))
histogram(y, horizontal = true, xflip = true)
# Draw a shade plot in the smaller top-left region
subplot(3, 3, 1)
shade(x, y)
source
- 4 - 2 0 2 4 - 4 - 2 0 2 4 0 5000 10000 15000 20000 - 4 - 2 0 2 4 - 4 - 2 0 2 4 0 5000 10000 15000 20000 - 4 - 2 0 2 4 - 4 - 2 0 2 4
GRUtils.holdFunction.
hold(flag::Bool)

Set the hold flag for combining multiple plots.

hold(true) prevents clearing previous plots, so that next plots will be drawn on top of the previous one until hold(false) is called.

Use the keyword argument hold=<true/false> in plotting functions, to set the hold flag during the creation of plots.

source
GRUtils.savefigFunction.
savefig(filename[, fig])

Save a figure to a file.

Draw the current figure in a file of the given name. Which file types are supported depends on the installed workstation types, but GR usually is built with support for .png, .jpg, .pdf, .ps, .gif and various other file formats.

If no figure is given (optional argument fig), the current figure is used.

Examples

# Create a simple plot
x = 1:100
plot(x, 1 ./ (x .+ 1))
# Save the figure to a file
savefig("example.png")
source