Improve multiple semantic legend titles
See original GitHub issueCurrently the legends for lineplot (#1285) and scatterplot (#1436) don’t indicate what variable each of the levels represent. I punted on this but it needs a solution. One option is to cram everything into the legend title but that’s not ideal. I think doing something with legend entries that have invisible handles and and then bumping the legend text so it looks centered would work:
f, ax = plt.subplots()
h1 = ax.scatter([], [], s=0, label="Title 1")
h2 = ax.scatter([], [], label="level 1")
h3 = ax.scatter([], [], s=0, label="Title 2")
h4 = ax.scatter([], [], label="level 2")
legend = ax.legend()
for t in legend.get_texts()[::2]:
xfm = transforms.offset_copy(t.get_transform(), ax.figure, x=-10, units="points")
t.set_transform(xfm)
But getting this to be really robust is going to be tricky.
Issue Analytics
- State:
- Created 5 years ago
- Comments:24 (24 by maintainers)
Top Results From Across the Web
How to change legend title in R using ggplot ? - GeeksforGeeks
Method 1: Using scale_colour_discrete() To change the legend title using this method, simply provide the required title as the value to its ......
Read more >Multiple titles in legend in matplotlib - python - Stack Overflow
After visiting dozens of questions here I came to this solution that works perfectly for me, but maybe there was a better way...
Read more >Legend guide — Matplotlib 3.6.2 documentation
Legend guide# · Controlling the legend entries# · Creating artists specifically for adding to the legend (aka. Proxy artists)# · Legend location# ·...
Read more >The Field Set Legend element - HTML - MDN Web Docs
<fieldset>. 2. <legend>Choose your favorite monster</legend>. 3. . 4. <input type="radio" id="kraken" name="monster" value="K">.
Read more >Semantic Highlight Guide | Visual Studio Code Extension API
Themes can opt in to use semantic tokens to improve and refine the syntax ... names the types and modifiers it's going to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Why not?
Ah I just saw your comment as I was coming to post this. I think checking on the legend artist visibility wouldn’t be too hard and be a more appropriate proxy than alpha because we can set the visibility of the handle afterwards. What I was just thinking is that instead of even adding the subtitles to the Axes at all (right now, we’re calling
ax.scatter([], [], label="title 1") solely for the label)
we don’t really want anything to do with thescatter
what if we had the user supply the ordering in a wrapper aroundax.legend()
? Sorry for throwing a billion ideas at you!