KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

How to make a plot with empty coordinates #304

Closed mroavi closed 1 year ago

mroavi commented 1 year ago

I'm trying to make a box plot using this code as an example.

In this example, they plot an empty set of coordinates {}. I noticed that PGFPlotsX.jl complains if I pass {} to the Coordinates constructor:

ERROR: LoadError: MethodError: no method matching length(::PGFPlotsX.Options)

Here is a minimal working example:

Code

```julia # Based on: https://tex.stackexchange.com/a/115438/23046 using PGFPlotsX # - https://arxiv.org/abs/2107.02270 push!(PGFPlotsX.CUSTOM_PREAMBLE,raw""" \usepackage{pgfplots} \pgfplotsset{compat=1.8} \usepgfplotslibrary{statistics} \usepackage{xcolor} \usepackage{tikz} \definecolor{c1}{HTML}{5790fc} """ ) tp = @pgf TikzPicture( Axis( # opts, { ytick = 1:3, yticklabels = ["Index 0", "Index 1", "Index 2"], }, PlotInc( { c1, boxplot_prepared = { median = 1, upper_quartile = 1.2, lower_quartile = 0.4, upper_whisker = 1.5, lower_whisker = 0.2, } }, Coordinates({}), ), ), ) ```

I've tried a bunch of variations of this code with no success.

This code works if I pass one point to Coordinates, but it plots the point as well:

Code

```julia # Based on: https://tex.stackexchange.com/a/115438/23046 using PGFPlotsX # - https://arxiv.org/abs/2107.02270 push!(PGFPlotsX.CUSTOM_PREAMBLE,raw""" \usepackage{pgfplots} \pgfplotsset{compat=1.8} \usepgfplotslibrary{statistics} \usepackage{xcolor} \usepackage{tikz} \definecolor{c1}{HTML}{5790fc} """ ) tp = @pgf TikzPicture( Axis( # opts, { ytick = 1:3, yticklabels = ["Index 0", "Index 1", "Index 2"], }, PlotInc( { c1, boxplot_prepared = { median = 1, upper_quartile = 1.2, lower_quartile = 0.4, upper_whisker = 1.5, lower_whisker = 0.2, } }, Coordinates([(0, 0)]), ), ), ) ```

image

I could make the point transparent, but I'm just wondering if there is a more elegant way to fix this.

tpapp commented 1 year ago

Coordinates({}) is invalid syntax, the {} has no place there. But even if you called it with an empty vector like [], it would not be able to determine the dimension.

Use Table([],[]) instead.

mroavi commented 1 year ago

Works great! Thanks @tpapp .