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.

Alpha appears to be ignored if it's constant for all datapoints:

See original GitHub issue

(why does github treat no text and enter as a valid issue… sorry about that).

An alpha aes is ignored when all instances have the same value. Observe:

p = plotnine.ggplot()
p += plotnine.geom_rect(
    plotnine.aes(xmin='xmin',xmax='xmax',ymin='ymin',ymax='ymax',fill='fill',
                alpha='alpha'),
          data = pd.DataFrame({
              'xmin': [0,0],
              'xmax': [1,0.5],
              'ymin': [0,0],
              'ymax': [1,0.5],
              'fill': ['red', 'blue'],
              'alpha': [0.5, 0.51]
          }),)
p += plotnine.scale_fill_identity()
p

Produces this, as expected. image

But replacing that second alpha value with 0.5:

p = plotnine.ggplot()
p += plotnine.geom_rect(
    plotnine.aes(xmin='xmin',xmax='xmax',ymin='ymin',ymax='ymax',fill='fill',
                alpha='alpha'),
          data = pd.DataFrame({
              'xmin': [0,0],
              'xmax': [1,0.5],
              'ymin': [0,0],
              'ymax': [1,0.5],
              'fill': ['red', 'blue'],
              'alpha': [0.5, 0.50]
          }),)
p += plotnine.scale_fill_identity()
p

image

I suspect this is also the underlying issue with #50 and #43 - arguably setting an aes to a scalar is something a user would expect - it’s documented to work for x and y in the API. But please note that this is a different case - we have a valid aes mapping that just happens to contain the same value for all instances and it’s completely ignored 😦.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
TyberiusPrimecommented, Sep 27, 2018

Hassan, I have the deepest respect for your work on plotnine. It is a truly beautiful library. May I suggest that “If you have any specific values, put them outside the aes() call.” would be better phrased as ‘if you have specific values, use an identity mapping’. This is the more general, and to my mind, more useful advice.

Yes that is the issue. This specific is not about discrete or continuous distinctions.

Indeed, it is about sensible default mappings.

Having scale_alpha_continuous(range(0.1, 1)) as the default scale trips new users, as evidenced by multiple bug reports.

How about switching to scale_alpha_identity() by default. It does not change ‘the meaning of what it means to map to a scale’ and it will explode with a (semi-useful) error message if you pass in something that needs one of the ‘true’ mappings.

But separately from the issue of the default scale for alpha, why does training scale_alpha_continuous((0.1,1)) on a single value map to an alpha of 1, while a scale_x_continuous will put your value in the middle of the plot?

I’d have expected it to map to 0.5.

0reactions
has2k1commented, Oct 1, 2018

I think rescale_pal is clear. The documentation that needs more examples is that for rescale, rescale_mid and rescale_max.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exponential Smoothing
ALPHA is the smoothing parameter that defines the weighting and should be greater than 0 and less than 1. ALPHA equal 0 sets...
Read more >
ECON 803 Midterm Review Flashcards - Quizlet
Which of these is not a consequence of ignoring autocorrelation if it is present? The coefficient estimates derived using OLS are biased.
Read more >
FAQ What is complete or quasi-complete separation in logistic ...
A complete separation happens when the outcome variable separates a predictor variable or a combination of predictor variables completely. Albert and Anderson ( ......
Read more >
Chapter 7: Correlation and Simple Linear Regression
A correlation exists between two variables when one of them is related to the ... every point; instead it balances the difference between...
Read more >
plotly.graph_objects.Scatter — 5.11.0 documentation
If a single string, the same string appears over all the data points. ... will be used - including if visible is “legendonly”...
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