Plot attributes
Titles
GRUtils.title
— Function.title(s)
Set the plot title as the string s
.
Examples
# Set the plot title to "Example Plot"
title("Example Plot")
# Clear the plot title
title("")
Axis guides
GRUtils.grid
— Function.grid(flag::Bool)
Draw or disable the grid of the current plot axes.
GRUtils.xlabel
— Function.xlabel(s)
ylabel(s)
zlabel(s)
Set the X, Y or Z axis labels as the string s
.
Examples
# Set the x-axis label to "x"
xlabel("x")
# Clear the y-axis label
ylabel("")
GRUtils.xticks
— Function.xticks(minor[, major = 1])
yticks(minor[, major = 1])
zticks(minor[, major = 1])
Set the minor
intervals of the ticks for the X, Y or Z axis, and (optionally) the number of minor ticks between major
ticks.
Examples
# Minor ticks every 0.2 units in the X axis
xticks(0.2)
# Major ticks every 1 unit (5 minor ticks) in the Y axis
yticks(0.2, 5)
GRUtils.xticklabels
— Function.xticklabels(f)
yticklabels(f)
Customize the string of the X and Y axes tick labels.
The labels of the tick axis can be defined by a function with one argument (the numeric value of the tick position) that returns a string, or by an array of strings that are located sequentially at X = 1, 2, etc.
Examples
# Label the range (0-1) of the Y-axis as percent values
yticklabels(p -> Base.Printf.@sprintf("%0.0f%%", 100p))
# Label the X-axis with a sequence of strings
xticklabels(["first", "second", "third"])
Axis dimensions
GRUtils.xlim
— Function.xlim(inf, sup [, adjust::Bool = false])
xlim((inf, sup), ...)
ylim(inf, sup, ...)
ylim((inf, sup), ...)
zlim(inf, sup, ...)
zlim((inf, sup), ...)
Set the limits for the plot axes.
The axis limits can either be passed as individual arguments or as a tuple of (inf, sup)
values. Setting either limit to nothing
will cause it to be automatically determined based on the data, which is the default behavior.
Additionally to the limits, the flag adjust
can be used to tell whether or not the limits have to be adjusted.
Examples
# Set the x-axis limits to -1 and 1
xlim((-1, 1))
# Reset the x-axis limits to be determined automatically
xlim()
# Set the y-axis upper limit and set the lower limit to 0
ylim((0, nothing))
# Reset the y-axis lower limit and set the upper limit to 1
ylim((nothing, 1))
GRUtils.aspectratio
— Function.aspectratio(r)
Set the aspect of the current plot to a given width : height ratio.
Examples
# Create example data
x = LinRange(-2, 2, 40)
y = x.^3 .+ x.^2 .+ x
# Draw a plot with panoramic ratio (16:9)
plot(x, y)
aspectratio(16/9)
GRUtils.zoom
— Function.zoom(s)
Zoom the current axes to the ratio indicated by s
.
The "zoomed" axes are centered around the same point, but proportionally resized to s
times the original size.
Examples
# Reduce the axes to half their size
zoom(0.5)
GRUtils.panzoom
— Function.panzoom(x, y[, s = 0])
Pan/zoom the axes of the current plot.
The focus of the zoom is set at a point with an offset of (x, y)
units in normalized device coordinates (NDC) from the center of the current axes. The corners of the axes are linearly displaced towards that point, such that the size of the new axes is s
times their original size.
If s
is set to 0 (the default value), the center of the axes is displaced at the focus, without resizing-
Example
# Move the center 1 unit right and 0.2 up (NDC)
panzoom(1, 0.2)
# Reduce the focus of the axes to half their size
# focusing on the previous point
panzoom(1, 0.2, 0.5)
Axis scales
GRUtils.xflip
— Function.xflip(flag::Bool)
yflip(flag::Bool)
zflip(flag::Bool)
Reverse the direction of the X-, Y- or Z-axis.
Examples
# Reverse the x-axis
xflip(true)
# Ensure that the y-axis is not reversed
yflip(false)
GRUtils.xlog
— Function.xlog(flag::Bool)
ylog(flag::Bool)
zlog(flag::Bool)
Set the X-, Y- or Z-axis to be drawn in logarithmic scale.
Examples
# Set the x-axis limits to log scale
xlog(true)
# Ensure that the y-axis is in linear scale
ylog(false)
GRUtils.radians
— Function.radians(flag::Bool)
Set the scale of angles in polar plots.
Use radians(true)
to represent angles in radians (default setting), and radians(false)
to represent them in degrees.
This operation only modifies the guides of the polar plot grid lines. The existing geometries are left without changes
Example
# Example data
θ = LinRange(0, 2π, 40)
r = sin.(θ)
# Draw the polar plot (by default in radians)
polar(θ, r)
# Change the angula scale
radians(false)
Geometry guides
GRUtils.legend
— Function.legend(labels...; kwargs...)
Set the legend of the plot, using a series of labels
(strings).
In addition to the legend strings, the keyword argument location
can be used to define the location of the legend with respect to the plot axes (as a number, following the convention of Matplotlib legends), and the keyword argument maxrows
to distribute the legend labels in a grid with a maximum number of rows.
The labels are assigned to the geometries contained in the plot, in the same order as they were created. Only geometries with non-empty labels and an available guide for legends.
Examples
# Set the legends to "a" and "b"
legend("a", "b")
GRUtils.colorbar
— Function.colorbar(flag::Bool)
Draw or disable the color bar in the current plot if available