
Is there a way to display only the legend box from a plot?
Context: I have several plots with the same legends, I want to draw the legend outside of them and not be bother with calculating sizes, so I want to draw the legend independently

No. This question came up in the past, and there is even an issue created for it, with a long comment section: https://github.com/racket/plot/issues/49

To confirm, these commits have been picked for v8.4

There is also an unmerged pull request for this: https://github.com/racket/plot/pull/73, I provided reasons for rejecting it, however, it should be a clean merge, so you can merge it in your own copy of the plot package and experiment if the feature is suitable for what you want. If it is, and you can provide examples, I would be happy to reconsider and merge it in.

Thank Alex, I’ll take a look. It’s not uncommon for me to have several plots to display side by side, with a common legend. Sometimes I can plot the legend inside one of the plots, but sometimes I want the legend at the left of the first plot, or above or below the plots, centered on the hc-append combined plots. The plot library currently has several issues for multiple plots: • x-min
and friends include the ticks size, which means that the actual plotting area can vary from picture to picture (which I want to avoid, most of the time) • the legend is attached to a plot. I can’t share my actual use cases as they involve unsharable data, but here’s a mock-up:

#lang racket
(require plot)
(for ([x-min '(0 100 1e5 1e10)]
[x-max '(100 1000 1e6 1e11)]
[i (in-naturals)])
(display
(plot
#:legend-anchor
(if (= i 0)
'outside-top
'no-legend)
#:width 300
#:x-min x-min
#:x-max x-max
(list (function sqrt #:label "√")
(function (λ (x) (sqr (log x)))
#:color 2 #:label "log²")))))

There is also the issue of the overlapping ticks. This group of plots represents fairly well some of the actual situations I happen to face

@ben same issues for you?

Of course 'outside-left
doesn’t work either, since it squashes the plot to the right

There is a separate issue for multiple plots too https://github.com/racket/plot/issues/7\|https://github.com/racket/plot/issues/7

Yes, this is a limitation of the plot package. Unfortunately I don’t know how to solve it in an elegant way that addresses all cases. I have some ideas, but didn’t have time to try them out

However, for your use case you could just manually create a legend using pict. It is actually not that complicated, I showed an example in one of the linked racket users threads. Not ideal, but might work

That’s a possibility, but far from ideal indeed. Plot already offers a good way to draw the legend automatically; as a user I don’t want to have to redo that. (Please let me be clear that I’m not complaining against anyone, and certainly not you, who’s helping on your free time.)

So would you consider the case above a good example justifying having something like the PR #49?

Possibly one simple workaround would be to have non-plot drawer, that draws only the legend without the plotting area.

Not perfect either unless plot is smart enough to not perform unnecessary computation is such cases

I had a quick look at racket-users but couldn’t find your example. However, it seems that the renderer2d
should have all the relevant information to draw a line with the provided style, in which case it may be easier than I thought.
But the renderer2d
struct is not provided. The fields can be extracted with struct->vector
but I don’t know what arguments they ask for

Yes Laurent, your code is similar to my use-case. I rarely use plot
though, and almost always use plot-pict
.

side note: Slack tags are not generally a reliable way to reach me.

Hi @laurent.orseau, sorry for not replying earlier, I went to bed last night and stopped reading messages. Anyway, to address some of your questions:
• you can use the pull request I linked to generate the plots you want. You don’t have to share them with me — if you tell me that you used it and it worked for you, that is all I need. • the pull request I linked to already uses the renderer2d
approach you suggested, you can study the code, if you want to try your own implementation • the message I mentioned for creating the legend separately is this one: https://groups.google.com/g/racket-users/c/QLfNmsluVHM/m/fTVCiCEKAgAJ

Finally, the issues that I linked to contain a lot of discutions and code references about this topic. I really don’t want to repeat the same arguments, sorry.

@popa.bogdanp, are observables in gui-easy thread-safe? If I obs-update!
from a different thread than the gui it won’t cause problems?

Yup, they are