Support adjusting the element size of legend
See original GitHub issueDescription
Sometimes, the plotted scatter size is small or big, we need to adjust the size in the legend to make it easier to read.
Steps to reproduce
import proplot as pplt
import numpy as np
def rand_data():
return np.random.uniform(low=0., high=1., size=(100,))
# Generate data.
x1, y1 = [rand_data() for i in range(2)]
x2, y2 = [rand_data() for i in range(2)]
fig, axs = pplt.subplots()
s1 = axs.scatter(x1, y1, marker='o', label='first', s=2, c='b')
s2 = axs.scatter(x2, y2, marker='o', label='second', s=3, c='r')
axs.legend([s1, s2], loc='r', ncols=1)
Expected behavior:
Support size=()
in axs.legend()
.
Actual behavior:
I have to adjust the scatter size in the legend manually:
legend = axs.legend([s1, s2], loc='r', ncols=1)
legend.legendHandles[0]._sizes = [30]
legend.legendHandles[1]._sizes = [30]
Equivalent steps in matplotlib
import matplotlib.pyplot as plt
import numpy as np
def rand_data():
return np.random.uniform(low=0., high=1., size=(100,))
# Generate data.
x1, y1 = [rand_data() for i in range(2)]
x2, y2 = [rand_data() for i in range(2)]
plt.figure()
plt.scatter(x1, y1, marker='o', label='first', s=2., c='b')
plt.scatter(x2, y2, marker='o', label='second', s=3., c='r')
# Plot legend.
lgnd = plt.legend(loc="lower right", scatterpoints=1, fontsize=10)
lgnd.legendHandles[0]._sizes = [30]
lgnd.legendHandles[1]._sizes = [30]
Proplot version
0.7.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Legend fitting strategies—ArcGIS Pro | Documentation
The Adjust columns fitting strategy automatically changes the number of columns to fit all items in the legend. The font sizes set in...
Read more >Problem: Unable to resize the legend in ArcGIS Pro
In the Element pane, click the Placement tab. Under Size, change the Width and Height of the legend item to the preferred size....
Read more >How to adjust the size of matplotlib legend box - Stack Overflow
To control the padding inside the legend (effectively making the legend box bigger) use the borderpad kwarg. For example, here's the default ...
Read more >The Field Set Legend element - HTML - MDN Web Docs
Tip: you can click/tap on a cell for more information. Full support: Full support. Deprecated. Not for use in new websites.
Read more >How to Change Legend Font Size in Matplotlib?
This example changes the font size of items in the legend. The font size parameter can have integer or float values. It also...
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 FreeTop 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
Top GitHub Comments
Yeah noticed that too… in your example it looks like you’re doing the equivalent of
Collection.set_sizes()
on the marker collection. In my example I’m doing the equivalent ofCollection.set_linewidth()
which (evidently) has some weird side-effects for this type of marker. I’ve added a 2-line workaround since this is probably a really common use-case for the “on-the-fly handle modification” feature. Now passingmarkersize=N
will update scatter marker sizes without the weird side effect – passingmarkersize
updates the collection withset_sizes()
.You can install the dev branch for this example to work:
pip install git+https://github.com/lukelbd/proplot.git
.Got it! Maybe, it’s better to add the example to the legend section? (many matplotlib questions on StackOverflow discussed something like this).