Opened 7 years ago

Last modified 7 years ago

#14580 closed enhancement

Set individual legend font color in Sage — at Version 1

Reported by: ppurka Owned by: jason, was
Priority: major Milestone: sage-5.12
Component: graphics Keywords:
Cc: sd45, sd48 Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by ppurka)

Currently, it is not possible to change the legend font color in Sage at all. This link shows how to do it in matplotlib - it is not straightforward in matplotlib either.

I think the way to introduce it is

  1. Allow a legend_color parameter to each plot.
  2. Keep track of the individual legend colors via a key in the Graphics._legend_opts dictionary.
  3. The key will contain a list of colors, defaulting to black or None (I prefer None, so that we use matplotlib's default).
  4. After all the plots have been rendered and the legend as been set, we can follow the method in the link above to extract all the texts and set the colors individually, skipping the ones which are None (if the default is None).

Apply trac_14580-legend_color.patch to devel/sage.

Change History (1)

comment:1 Changed 7 years ago by ppurka

  • Description modified (diff)
  • Status changed from new to needs_review

I added a new attribute self._legend_colors = [] to Graphics. This will hold the colors or None in case no colors are provided. Patch needs review.

Edit: It is now possible to get a graph like this:

sage: p1 = plot(x, legend_label='this is x', legend_color='red', color='red')
sage: p2 = plot(x**2, legend_label='this is x^2', legend_color='green', color='green')
sage: (p1+p2).save('/tmp/a.png')
Last edited 7 years ago by ppurka (previous) (diff)
Note: See TracTickets for help on using tickets.