question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Too many decimal places in legend labs for relplot with hue or size keywords

See original GitHub issue

I ran into this problem with a particular dataset. Calling replot with either hue or size causes extremely long labels in the legend because of what looks like floating point arithmetic in the labeling logic.

Example:

test = pd.DataFrame({
 'foo' :[1,2,3,4,5,6,7],
 'bar' :[4,6,8,3,5,4,6],
    'baz':[0.4, 0.19, 0.35, 0.22, 0.35, 0.31, 0.09]
}
)
sns.relplot(
data=test.head(7),
x='foo',
y='bar',
size='baz')

Selection_006

Is there some way that the legend labels could be rounded or otherwise formatted to prevent this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
mojonescommented, Mar 22, 2019

Workaround for anyone else who finds themselves looking at this:

plot =sns.relplot(
data=test.head(7),
x='foo',
y='bar',
size='baz')

leg = plot._legend
for t in leg.texts:
    # truncate label text to 4 characters
    t.set_text(t.get_text()[:4])
0reactions
mwaskomcommented, Jan 20, 2020

The specific example at the beginning of this thread now produces the expected result, so if you are having a problem in some other context, you need to provide a reproducible example that demonstrates it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Legend In Seaborn Scatter Plot: How To Limit The Number Of ...
To make a legend for lines which already exist on the Axes (via plot for instance), ... Too many decimal places in legend...
Read more >
How to get rid of decimal point in the legend - Stack Overflow
I wanted to know how I could get rid of the decimals in the legend. So instead of 1.0 it will be just...
Read more >
seaborn.relplot — seaborn 0.12.1 documentation - PyData |
If “brief”, numeric hue and size variables will be represented with a sample of evenly spaced values. If “full”, every group will get...
Read more >
Statistics and Machine Learning in Python - Archive ouverte HAL
Like lists, but their size cannot change: ordered, iterable, immutable, can contain multiple data types. # create a tuple digits = (0, 1 ......
Read more >
Stack Overflow Answers by Trenton McKinney
CreationDate ViewCount Score Accepted 0 2021‑12‑16 44 0 True 1 2021‑12‑13 67 1 True 2 2021‑12‑09 7636 0 False
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found