Coordinates

Coordinates

Use Coordinates to construct the pgfplots construct coordinates. Various constructors are available.

Basic usage

For basic usage, consider AbstractVectors and iterables. Notice how non-finite values are skipped. You can also use () or nothing for jumps in functions.

x = linspace(-1, 1, 51) # so that it contains 1/0
@pgf Axis(
    {
        xmajorgrids,
        ymajorgrids,
    },
    Plot(
        {
            no_marks,
        },
        Coordinates(x, 1 ./ x)
    )
)

[.pdf], [generated .tex]

Error bars

Use xerror, xerrorplus, xerrorminus, yerror etc. for error bars.

x = linspace(0, 2π, 20)
@pgf Plot(
    {
        "no marks",
        "error bars/y dir=both",
        "error bars/y explicit",
    },
    Coordinates(x, sin.(x); yerror = 0.2*cos.(x))
)

[.pdf], [generated .tex]

3D

Use three vectors to construct 3D coordinates.

t = linspace(0, 6*π, 100)
@pgf Plot3(
    {
        no_marks,
    },
    Coordinates(t .* sin.(t), t .* cos.(t), .-t)
)

[.pdf], [generated .tex]

Edge vectors

A convenience constructor is available for plotting a matrix of values calculated from edge vectors.

x = linspace(-2, 2, 20)
y = linspace(-0.5, 3, 25)
f(x, y) = (1 - x)^2 + 100*(y - x^2)^2
@pgf Plot3(
    {
        surf,
    },
    Coordinates(x, y, f.(x, y'))
)

[.pdf], [generated .tex]

Heatmap

x = linspace(-2, 2, 40)
y = linspace(-0.5, 3, 50)
@pgf Axis(
    {
        view = (0, 90),
        colorbar,
        "colormap/jet",
    },
    Plot3(
        {
            surf,
            shader = "flat",
        },
        Coordinates(x, y, @. √(f(x, y')))
    )
)

[.pdf], [generated .tex]

Matrix plot

x = repeat(0:2, outer = 3)
y = repeat(0:2, inner = 3)
meta = ["color=$c" for c in ["red", "blue", "yellow", "black", "brown", "magenta", "green", "red", "white"]]
c = Coordinates(x, y; meta = meta)
@pgf Axis(
    {
        enlargelimits = false,
        xtick = [0, 1, 2]
    },
    PlotInc(
        {
            matrix_plot,
            mark = "*",
            nodes_near_coords = raw"\coordindex",
            "mesh/color input" = "explicit",
            "mesh/cols" = 3
        },
        c,
    )
)

[.pdf], [generated .tex]