Opened 6 years ago
Closed 6 years ago
#14580 closed enhancement (fixed)
Set individual legend font color in Sage
Reported by: | ppurka | Owned by: | jason, was |
---|---|---|---|
Priority: | major | Milestone: | sage-5.12 |
Component: | graphics | Keywords: | |
Cc: | sd45, sd48 | Merged in: | sage-5.12.beta2 |
Authors: | Punarbasu Purkayastha, Karl-Dieter Crisman | Reviewers: | Karl-Dieter Crisman, Punarbasu Purkayastha |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | #13834 | Stopgaps: |
Description (last modified by )
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
- Allow a
legend_color
parameter to each plot. - Keep track of the individual legend colors via a key in the
Graphics._legend_opts
dictionary. - The key will contain a list of colors, defaulting to black or None (I prefer None, so that we use matplotlib's default).
- 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 and trac_14580-more-colors-rebased.patch to devel/sage.
Attachments (3)
Change History (18)
comment:1 Changed 6 years ago by
- Description modified (diff)
- Status changed from new to needs_review
comment:2 Changed 6 years ago by
- Status changed from needs_review to needs_work
- Work issues set to fix doctests
comment:3 Changed 6 years ago by
- Status changed from needs_work to needs_review
- Work issues fix doctests deleted
comment:4 Changed 6 years ago by
comment:5 Changed 6 years ago by
I think this is very intriguing. I spent a lot of time thinking about why the existing legend suboptions decorator might not work, and how this code magically allows examples to work in different orders, and I think this is really correct. So this is my only question:
- Tons of other graphics primitives have legends (arrow, disk, etc.), which do not use
point
orline
. Presumably we should support those too?
comment:6 Changed 6 years ago by
$ grep -r p.set_label sage/plot/ sage/plot/arrow.py: p.set_label(options['legend_label']) sage/plot/arrow.py: p.set_label(options['legend_label']) sage/plot/circle.py: p.set_label(options['legend_label']) sage/plot/disk.py: p.set_label(options['legend_label']) sage/plot/ellipse.py: p.set_label(options['legend_label']) sage/plot/line.py: p.set_label(options['legend_label']) sage/plot/polygon.py: p.set_label(options['legend_label'])
comment:7 Changed 6 years ago by
- Cc sd45 added
- Reviewers set to Karl-Dieter Crisman
comment:8 Changed 6 years ago by
There is also not a doctest for the point
version yet. I'll try to write a second patch now, which would definitely need review.
Changed 6 years ago by
comment:9 Changed 6 years ago by
- Cc sd48 added
- Description modified (diff)
Patchbot, apply trac_14580-legend_color.patch and trac_14580-more-colors.patch
comment:10 Changed 6 years ago by
- Reviewers changed from Karl-Dieter Crisman to Karl-Dieter Crisman, Punarbasu Purkayastha
- Status changed from needs_review to positive_review
Don't know why the patchbot refuses to test your new patch. It passes all tests in devel/sage/sage/plot. I see no issues with your patch.
comment:11 Changed 6 years ago by
- Dependencies set to #13834
- Milestone changed from sage-5.11 to sage-5.12
This needs to be rebased to #13834.
comment:12 Changed 6 years ago by
- Status changed from positive_review to needs_work
comment:13 Changed 6 years ago by
- Description modified (diff)
- Status changed from needs_work to positive_review
Rebased both the patches against #13834
comment:14 Changed 6 years ago by
patchbot apply trac_14580-legend_color.patch trac_14580-more-colors-rebased.patch
comment:15 Changed 6 years ago by
- Merged in set to sage-5.12.beta2
- Resolution set to fixed
- Status changed from positive_review to closed
I added a new attribute
self._legend_colors = []
toGraphics
. This will hold the colors orNone
in case no colors are provided. Patch needs review.