Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Cannot set annotation font style without Plots dependency #72

Closed
anowacki opened this issue Jun 3, 2020 · 4 comments
Closed

Cannot set annotation font style without Plots dependency #72

anowacki opened this issue Jun 3, 2020 · 4 comments

Comments

@anowacki
Copy link

anowacki commented Jun 3, 2020

This is a long-standing issue (e.g., see here), but one I still bump up against, though I can't find a specific issue here or in Plots for it.

I would like to be able to define the format (family, size, colour, etc.) of series annotations in recipes (with series_annotations), but I do not want to depend on Plots, and this is currently impossible. There is currently no way to set these properties without using Plots.text and thereby Plots.font. The fix for JuliaPlots/Plots.jl#555 (JuliaPlots/Plots.jl@f2e2ffa) now allows one to use recipes to set font attributes for labels, but not annotations on plots themselves. The workaround here does not work in all cases—for instance when the calling module has loaded Plots, but not in to Main—and is pretty brittle in any case.

Though I don't much understand RecipesBase or Plots internals, for me as a user it would make sense to set attributes similar those introduced by JuliaPlots/Plots.jl@f2e2ffa, and in recipes use (for example) :annotfontfamily, :annotfontsize and so on to set annotation font parameters.

@mkborregaard
Copy link
Member

This commit: JuliaPlots/Plots.jl@7acb5a4 was intended to fix this, allowing passing a tuple instead to annotations. I know for a fact that it used to work, but something might have changed.

@mkborregaard
Copy link
Member

So this works

struct MyType end
@recipe function f(x::MyType)
       annotations := (2, 4, ( "test", :right, 20))
       1:10, 1:10
end
plot(MyType())

@BeastyBlacksmith
Copy link
Member

Might be relevant: JuliaPlots/Plots.jl#3463

@anowacki
Copy link
Author

anowacki commented Jul 6, 2021

Thanks very much! I hadn't realised that passing tuples (edit: of arguments to Plots.text) was possible, and this solves my issue.

When time allows I'll submit a PR to add this to the docs (specifically the attributes list here and here for each backend). I can't find this mentioned anywhere and so I think that's why I hadn't realised it could be done.

Edit: I now see that this is in NEWS.md for version 0.22.2.

anowacki added a commit to anowacki/Seis.jl that referenced this issue Jul 7, 2021
Pick labels are now drawn using bare tuples as `annotations` to
a plot series (see
JuliaPlots/Plots.jl@7acb5a4
and JuliaPlots/RecipesBase.jl#72)
rather than via a hack to get the `Plots` module from `Main`.
anowacki added a commit to anowacki/Seis.jl that referenced this issue Jul 7, 2021
Pick labels are now drawn using bare tuples as `annotations` to
a plot series (see
JuliaPlots/Plots.jl@7acb5a4
and JuliaPlots/RecipesBase.jl#72)
rather than via a hack to get the `Plots` module from `Main`.

In summary, Plots.jl now allows the `annotations` attribute
to contain `(x, y, (text, text_args...))`, where `text_args...`
are passed to the `Plots.text` constructor.
anowacki added a commit to anowacki/Seis.jl that referenced this issue Jul 7, 2021
Pick labels are now drawn using bare tuples as `annotations` to
a plot series (see
JuliaPlots/Plots.jl@7acb5a4
and JuliaPlots/RecipesBase.jl#72)
rather than via a hack to get the `Plots` module from `Main`.

Specifically, Plots.jl now allows the `annotations` attribute
to contain `(x, y, (text, text_args...))`, where `text_args...`
are passed to the `Plots.text` constructor.
anowacki added a commit to anowacki/Seis.jl that referenced this issue Jul 7, 2021
Pick labels are now drawn using bare tuples as `annotations` to
a plot series (see
JuliaPlots/Plots.jl@7acb5a4
and JuliaPlots/RecipesBase.jl#72)
rather than via a hack to get the `Plots` module from `Main`.

Specifically, Plots.jl now allows the `annotations` attribute
to contain `(x, y, (text, text_args...))`, where `text_args...`
are passed to the `Plots.text` constructor.

Previously we use `series_annotations` to simultaneously plot
symbols and text at those points.  (Note that `series_annotations`
**does not** support plain tuples and requires a call to
`Plots.text` to format the series annotations.)  Now we plot a
separate, empty series with `annotations` set.
anowacki added a commit to anowacki/Plots.jl that referenced this issue Jul 7, 2021
The `annotations` attribute (and `annotate!` function) has supported
the use of plain tuples containing arguments which are passed to
`text` since v0.22.2.  Document this option in the list of SubPlot
attributes and in example 20.

Closes (mostly) JuliaPlots/RecipesBase.jl#72
but note that `series_annotations` does not yet support passing tuples
of arguments for `Plots.text`.
anowacki added a commit to anowacki/PlotDocs.jl that referenced this issue Jul 7, 2021
Companion to JuliaPlots/Plots.jl#3628

The `annotations` attribute (and `annotate!` function) has supported
the use of plain tuples containing arguments which are passed to
`text` since v0.22.2.  Document this option for example 20 for the
InspectDR backend (not autogenerated).

Closes (mostly) JuliaPlots/RecipesBase.jl#72
anowacki added a commit to anowacki/Plots.jl that referenced this issue Jul 8, 2021
The `annotations` attribute (and `annotate!` function) has supported
the use of plain tuples containing arguments which are passed to
`text` since v0.22.2.  Document this option in the list of SubPlot
attributes and in example 20.

Closes (mostly) JuliaPlots/RecipesBase.jl#72
but note that `series_annotations` does not yet support passing tuples
of arguments for `Plots.text`.
anowacki added a commit to anowacki/Plots.jl that referenced this issue Jul 8, 2021
The `annotations` attribute (and `annotate!` function) has supported
the use of plain tuples containing arguments which are passed to
`text` since v0.22.2.  Document this option in the list of SubPlot
attributes and in example 20.

Closes (mostly) JuliaPlots/RecipesBase.jl#72
but note that `series_annotations` does not yet support passing tuples
of arguments for `Plots.text`.
@t-bltg t-bltg closed this as completed Aug 2, 2021
BeastyBlacksmith pushed a commit to JuliaPlots/PlotDocs.jl that referenced this issue Jun 7, 2022
Companion to JuliaPlots/Plots.jl#3628

The `annotations` attribute (and `annotate!` function) has supported
the use of plain tuples containing arguments which are passed to
`text` since v0.22.2.  Document this option for example 20 for the
InspectDR backend (not autogenerated).

Closes (mostly) JuliaPlots/RecipesBase.jl#72
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants