Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use colorblind-friendly colors in the scatter plots gallery example #1013

Merged
merged 7 commits into from
Apr 12, 2021
Merged

Conversation

vitorgt
Copy link
Contributor

@vitorgt vitorgt commented Mar 6, 2021

#1011

I'm replying to an open good first issue (#1011), using color names defined in GMT docs as referred by @weiji14 (thanks).

Fixes #1011

@welcome
Copy link

welcome bot commented Mar 6, 2021

💖 Thanks for opening this pull request! 💖

Please make sure you read our contributing guidelines and abide by our code of conduct.

A few things to keep in mind:

  • If you need help writing tests, take a look at the existing ones for inspiration. If you don't know where to start, let us know and we'll walk you through it.
  • All new features should be documented. It helps to write the docstrings for your functions/classes before writing the code. This will help you think about your code design and results in better code.
  • No matter what, we are really grateful that you put in the effort to do this! 🎉

@seisman seisman added the documentation Improvements or additions to documentation label Mar 6, 2021
@seisman seisman added this to the 0.3.1 milestone Mar 6, 2021
@seisman seisman requested a review from weiji14 March 6, 2021 19:18
@@ -21,7 +21,7 @@
projection="X10c/10c",
frame=["xa0.2fg", "ya0.2fg", "WSrt"],
)
for color in ["blue", "orange", "green"]:
for color in ["seagreen2", "chocolate1", "mediumpurple1"]:
Copy link
Member

@michaelgrund michaelgrund Mar 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for color in ["seagreen2", "chocolate1", "mediumpurple1"]:
for color in ["seagreen2", "chocolate1", "mediumpurple1"]:

Not sure if these colors solve the problem (please correct me if I'm wrong). Maybe it would be better to select colors from cpts that really focus on the color blindness issue.

Here's a deuteranopia (green-blind) simulation of your example @vitorgt:

deuteranopia

By the way, here's a nice article about the use (or misuse) of color in scientific visualization by Crameri et al.: https://www.nature.com/articles/s41467-020-19160-7.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but colorblind friendly colorschemes are very limited, and transparency makes this case even worst, I've changed green to a grey, this change will produce greater differences on protanopia and deuteranopia, but purple will get closer to grey on tritanopia (the rarest of the three).

Everywhere i looked on how to choose colorblind friendly colors they say not to rely only color, but to create other ways to differentiate set, usualy changing marker. So i added this.

Also, i couldn't find colorblind friendly cpts on gmt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transparency makes this case even worst,

Perhaps we can try to increase the transparency slightly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transparency makes this case even worst,

Perhaps we can try to increase the transparency slightly?

Agree, perhaps transparency=50 gives a better result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, @michaelgrund, "transparency makes this case even worst" means we sould remove transparency.
Like transparency=90 or remove that line completely (which would be equal to transparency=100 (default)).

Transparenncy makes it worst beacuse it blends the colors and changes their luminance when adding two or more symbols with equal or different colors, notting that color addition with colorblindness is a little bit tricky. That's why transparency should be avoided if we want it more coverage considering colorblindness.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're getting a bit confused here. transparency=0 means opaque while transparency=100 means invincible. We probably want to reduce transparency (i.e. increase opacity).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right @weiji14. I think we should not drop transparency here since it allows to deal with overplotting.

@michaelgrund michaelgrund marked this pull request as draft March 7, 2021 19:11
@michaelgrund
Copy link
Member

Converted the PR to draft to save resources.

# and set the circle size to be 0.25 cm (+S0.25c) in legend
label=f"{color}+S0.25c",
# and set the style size to be 0.25 cm (+S0.25{style}) in legend
label=f"{color}+S0.25{style}",
transparency=70, # set transparency level for all symbols
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
transparency=70, # set transparency level for all symbols
transparency=50, # set transparency level for all symbols

Perhaps 50 gives a better result.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please try 50, i.e. less transparency (more opaque). See also #1013 (comment).

# and set the circle size to be 0.25 cm (+S0.25c) in legend
label=f"{color}+S0.25c",
# and set the style size to be 0.25 cm (+S0.25{style}) in legend
label=f"{color}+S0.25{style}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the warning at https://pygmt-ln1ssu8ap-gmt.vercel.app/gallery/plot/scatter.html#sphx-glr-gallery-plot-scatter-py:

plot [WARNING]: Length <unit> s not supported - revert to default unit [cm]
plot [WARNING]: Length <unit> t not supported - revert to default unit [cm]

0.25c means 0.25 cm, so we shouldn't use style as the unit. If we'd like to change the size for each symbol in the legend, it'd better to also add it in the for loop. But I feel 0.25c is okay for those three symbols.

Suggested change
label=f"{color}+S0.25{style}",
label=f"{color}+S0.25c",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much, and I'm sorry, I didn't know that, I thought it was the symbol to show, not the size in cm. Appreciated.

sizes=sizes,
color=color,
# Set the legend label,
# and set the circle size to be 0.25 cm (+S0.25c) in legend
label=f"{color}+S0.25c",
# and set the style size to be 0.25 cm (+S0.25{style}) in legend
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# and set the style size to be 0.25 cm (+S0.25{style}) in legend
# and set the style size to be 0.25 cm (+S0.25c) in legend

@seisman
Copy link
Member

seisman commented Mar 12, 2021

Everywhere i looked on how to choose colorblind friendly colors they say not to rely only color, but to create other ways to differentiate set, usualy changing marker.

I agree with it, but I think the example is focusing on different colors, not "different colors and different symbols" (we could add another example for it).

I think we should only make changes to colors in this PR.

@seisman seisman modified the milestones: 0.3.1, 0.4.0 Mar 14, 2021
@vitorgt
Copy link
Contributor Author

vitorgt commented Mar 14, 2021

Everywhere i looked on how to choose colorblind friendly colors they say not to rely only color, but to create other ways to differentiate set, usualy changing marker.

I agree with it, but I think the example is focusing on different colors, not "different colors and different symbols" (we could add another example for it).

I think we should only make changes to colors in this PR.

@seisman, I kinda disagree with that, the example says:

To create a scatter plot with a legend one may use a loop and create one scatter plot per item to appear in the legend and set the label accordingly.

It doesn't specify its focus, nor restrics the "legend" or the "label" to deal only with colors, and I reaffirm, color blindness accessibility must not rely only on colors, but I'm not a member of GMT, you have far more context within the project than I do, I'll do whatever you members think fits.

Before I continue I need to know:

  • Do you want symbols to change?
  • Do you want transparency to change? (Please note this new reply)
  • Are the new colors ok? (["gray73", "darkorange", "slateblue"] I tried to plot them locally but i'm getting an impossible to solve error with "libgmt.so". I've checked them on color blindness tests but this case is special and a plot proof needs to be made)

@weiji14
Copy link
Member

weiji14 commented Mar 15, 2021

  • Are the new colors ok? (["gray73", "darkorange", "slateblue"] I tried to plot them locally but i'm getting an impossible to solve error with "libgmt.so". I've checked them on color blindness tests but this case is special and a plot proof needs to be made)

Apologies for the late reply @vitorgt, the colours look great! But we could decrease the transparency a bit (i.e. increase opacity) as suggested at #1013 (comment)

Original Deuteranopia
Original colour Deuteranopia simulated colour
  • Do you want symbols to change?

Could you try changing it back to circles only to see what it looks like?

Oh, and just FYI, we have a Continuous Documentation setup, so you can check the live preview at https://pygmt-git-fork-vitorgt-patch-1-gmt.vercel.app/gallery/plot/scatter.html. Sorry for not mentioning it earlier.

@maxrjones
Copy link
Member

maxrjones commented Mar 15, 2021

Personally, I find that the transparency makes it more difficult to see the data points and would prefer to see the transparency parameter removed as @vitorgt suggested. Why not just reduce the overplotting? Gaussian noise alone isn't that interesting to plot anyways. Something like this could be a good compromise (warning: the plotting parameters are not pretty and the comments aren't accurate - just showing the idea here):

Edit: one more point: I think adding pen to fig.plot() would also improve the visibility.

import numpy as np
import pygmt

np.random.seed(19680801)
n = 30  # number of random data points

fig = pygmt.Figure()
fig.basemap(
    region=[-10, 110, -10, 350],
    projection="X10c/10c",
    frame=["xa20fg", "ya50fg", "WSrt"],
)
for color, style, slope in [("gray73", "c", 1), ("darkorange", "s", 2), ("slateblue", "t", 3)]:
    x = np.linspace(0, 100, n)
    y = (slope*x) + 3*np.random.randn(n)  # random X and Y data in [0,1]
    sizes = np.random.normal(1,0.2,n) * 0.3  # random size [0,0.5], in cm
    # plot data points as circles (style="c"), with different sizes
    fig.plot(
        x=x,
        y=y,
        style=style,
        sizes=sizes,
        color=color,
        pen="black",
        # Set the legend label,
        # and set the style size to be 0.25 cm (+S0.25{style}) in legend
        label=f"{color}+S0.25c",
    )

fig.legend(position="JTL+o-3/-2c", box="+gwhite+pblack")  # set transparency level for legends
fig.show()

image

@maxrjones
Copy link
Member

Thanks, @vitorgt for addressing this issue. Since the transparency/overplotting was not part of the initial accessible colors issue, it can be addressed separately and to wrap this up you can commit the suggestions from @core-man and @seisman and the reduced transparency suggestion by @michaelgrund whenever you get a chance. Here are specific answers to your previous questions:

Before I continue I need to know:

Do you want symbols to change?

No, your points are well made and the new symbol selections are fine.

Do you want transparency to change? (Please note this new reply)

Yes, please commit this suggestion: https://github.com/GenericMappingTools/pygmt/pull/1013/files#r589324327. After this gets merged, the transparency and overplotting can be dealt with in a separate PR. You are more than welcome to open the next PR for the gallery example or leave it at this important contribution of improving the colors and adding distinct symbols.

Are the new colors ok? (["gray73", "darkorange", "slateblue"] I tried to plot them locally but i'm getting an impossible to solve error with "libgmt.so". I've checked them on color blindness tests but this case is special and a plot proof needs to be made)

Yes, as @weiji14 mentioned the new colors are good.

If you are OK with the suggestions, then you can click 'Files changed' in the PR and add the four suggested revisions to a batch commit using the 'Add suggestion to batch' option before committing them all.

@seisman
Copy link
Member

seisman commented Apr 2, 2021

Ping @vitorgt to see if you have time to finalize this PR.

@vitorgt
Copy link
Contributor Author

vitorgt commented Apr 6, 2021

Sorry for the late reply
I've moved back to circles and made them more opaque :)
@meghanrjones sorry, i couldn't do the 'Add suggestion to batch', so I just made a new commit with the changes

Copy link
Member

@michaelgrund michaelgrund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move the example into the newly created gallery/symbols folder @vitorgt ?

@seisman seisman marked this pull request as ready for review April 10, 2021 19:43
Copy link
Member

@michaelgrund michaelgrund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@michaelgrund michaelgrund added the final review call This PR requires final review and approval from a second reviewer label Apr 11, 2021
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Apr 12, 2021
@seisman seisman changed the title Accessible colors for color blindness Use colorblind-friendly colors in the scatter plots gallery example Apr 12, 2021
@seisman seisman merged commit d5658aa into GenericMappingTools:master Apr 12, 2021
@welcome
Copy link

welcome bot commented Apr 12, 2021

🎉🎉🎉 Congrats on merging your first pull request and welcome to the team! 🎉🎉🎉

Please open a new pull request to add yourself to the AUTHORS.md file. We hope that this was a good experience for you. Let us know if there is any way that the contributing process could be improved.

@vitorgt vitorgt deleted the patch-1 branch April 14, 2021 02:10
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make scatter plots gallery example colourblind friendly
6 participants