plot legends

40 views
Skip to first unread message

Matt Jadud

unread,
Dec 1, 2018, 3:47:22 PM12/1/18
to racket...@googlegroups.com
Hi all,

I'm starting to think about courses for next year, and I'd really like to move to Racket for working with data with my students. For me, this is going to involve thinking about a package or packages that move some plotting and data work down into the HtDP space.

For now, I'm just playing. One of the first things that I've run into with plotting is that I'd like to put the legends outside of the area in which data is plotted. (Put another way, I'd like my legend to appear to the right of #:x-max.)

Is this possible using the existing library, or would this require discussion/modifications and a pull request against the plot package?

Many thanks,
Matt

Ben Greenman

unread,
Dec 1, 2018, 4:14:09 PM12/1/18
to Matt Jadud, racket...@googlegroups.com
I think this requires discussion & modification.

E.g.: https://github.com/racket/plot/issues/49

Matt Jadud

unread,
Dec 1, 2018, 5:11:24 PM12/1/18
to Ben Greenman, racket...@googlegroups.com
So, is the discussion "are you going to do it, or me?" 

:D

Humor aside, I'll take a look, and report back thoughts here. Or, visa-versa. (Or, if there is a better space for this conversation, somewhere else.)

Thanks for the pointer to the ticket.

Cheers,
M

Alex Harsanyi

unread,
Dec 1, 2018, 5:31:35 PM12/1/18
to Racket Users

There was a similar question asked on this group a while ago.  tThe plot library does not support legends outside the plot area, but you can use the pict package to construct your own legend and place it anywhere.  This requires some coding, but provides more flexibility (for example,  you can also change the way the legend is drawn.)


Alex.

Matt Jadud

unread,
Dec 1, 2018, 6:10:36 PM12/1/18
to Alex Harsanyi, racket...@googlegroups.com
Thanks for the pointer; I should have searched the group history before asking. And, perhaps, the ticket queue.

For what I'm exploring right now, that would be just fine, and makes perfect sense, and will let me proceed with explorations without (yet) making pull requests. 

However, I personally feel like the enhancement that Ben pointed to is a good one. Being able to say 

'outer-upper-right
'outer-upper-left
...

(for example, and so on) as additional legend positions (so as to not change the current language around legend placement) would be nice. While I might, sometimes, want the legend inside the range of my axes, I personally can imagine often wanting it outside of the "plot area." 

Cheers,
M

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Harsanyi

unread,
Dec 1, 2018, 10:54:19 PM12/1/18
to Racket Users


On Sunday, December 2, 2018 at 7:10:36 AM UTC+8, Matt Jadud wrote:
Thanks for the pointer; I should have searched the group history before asking. And, perhaps, the ticket queue.

For what I'm exploring right now, that would be just fine, and makes perfect sense, and will let me proceed with explorations without (yet) making pull requests. 

However, I personally feel like the enhancement that Ben pointed to is a good one.

The enhancement is indeed a good one, but the implementation it is not
trivial.  The problem is that there is no "outer area" in the plot where to
put the legend in.  When the plot library allocates space for the different
plot elements (labels, axes, plot area, etc), it does not consider the legend,
but instead it assumes that it will be placed somewhere inside the plot area.
This means that, before an anchor such as 'outer-upper-right can be translated
into x,y coordinates for the drawing, the code will need to be updated to
make room for the legend if it needs to be outside the plot area.

I know roughly what needs to be done, and I can point you in the right
direction, if you are interested, but I don't have time to make these changes
myself.

The linked enhancement request, https://github.com/racket/plot/issues/49,
proposes a different approach, where the plot functions would return two
pictures, one for the plot itself and another for the plot legend, with the
expectation that the user will combine them.  This is somewhat similar to what
I showed in my example, except my code constructed the legend "manually" and
therefore might get out of sync with the plot data.

Implementing this approach would not be any simpler, in my opinion, and it
will involve a bigger API change.

Alex.
 

Reply all
Reply to author
Forward
0 new messages