Skip to content

DOC: colormap-manipulation tutorial #11905

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

Merged
merged 6 commits into from
Aug 25, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Aug 21, 2018

PR Summary

closes #11903

Shows how to manipulate colormaps.

rendered version 24 Aug: https://12782-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/tutorials/colors/colormap-manipulation.html#sphx-glr-tutorials-colors-colormap-manipulation-py

PR Checklist

  • Needs links in API docs...
  • Code is PEP 8 compliant
  • Documentation is sphinx and numpydoc compliant

@jklymak
Copy link
Member Author

jklymak commented Aug 21, 2018

This is ready for suggestion (but not formal review, as I've not linked everything, nor squashed all flake8 complaints)

https://12679-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/tutorials/colors/colormap-manipulation.html#sphx-glr-tutorials-colors-colormap-manipulation-py

@jklymak jklymak force-pushed the doc-add-colormap-manipulation branch 5 times, most recently from a0582fc to 2d51a38 Compare August 22, 2018 17:08
@jklymak jklymak force-pushed the doc-add-colormap-manipulation branch from 2d51a38 to f58f5f3 Compare August 22, 2018 17:57
@jklymak jklymak changed the title [WIP] DOC: colormap-manipulation tutorial DOC: colormap-manipulation tutorial Aug 22, 2018
@jklymak jklymak requested a review from afvincent August 22, 2018 18:29
# 0.5 of the colormap.

viridis = cm.get_cmap('viridis', 256)
newcmp = ListedColormap(viridis(np.linspace(0.25, 0.75, 256)))
Copy link
Member

Choose a reason for hiding this comment

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

Will this have over-sampling issues?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooops, yes it will. Not really noticeable at 256 resolution, but would certainly be a problem for small colormaps. Changed to

# We can easily reduce the dynamic range of a colormap; here we choose the middle
# 0.5 of the colormap.  However, we need to interpolate from a larger
# colormap, otherwise the new colormap will have repeated values.

viridisBig = cm.get_cmap('viridis', 512)
newcmp = ListedColormap(viridisBig(np.linspace(0.25, 0.75, 256)))
plot_examples([viridis, newcmp])

@tacaswell tacaswell added this to the v2.2-doc milestone Aug 23, 2018
@tacaswell
Copy link
Member

Overall I like this!

I might tone down selling how hard this is in the top of the tutorial a bit.

@jklymak
Copy link
Member Author

jklymak commented Aug 23, 2018

I might tone down selling how hard this is in the top of the tutorial a bit.

Fair enough - I shouldn't point out my own confusion in tutorials. First two paragraphs now just one:


Creating and manipulating colormaps in Matplotlib is quite straight-forward
using the class `.ListedColormap` and a Nx4 numpy array of values
between 0 and 1 to represent the RGBA values of the colormap.  There
is also a `.LinearSegmentedColormap` class that allows colormaps to be
specified with far fewer anchor points defining segments, and linearly
interpolating between the anchor points.

@tacaswell
Copy link
Member

I added a one word commit (removed 'quite' as I think it falls into the same category as 'just' as a word that can be read by people who don't already know the next part of the sentence as "only dumb people do not know ..." ).

@@ -1,8 +1,13 @@
"""
Builtin colormaps, colormap handling utilities, and the `ScalarMappable` mixin.
See :doc:`/gallery/color/colormap_reference` for a list of builtin colormaps.
See :doc:`/tutorials/colors/colormaps` for an in-depth discussion of colormaps.
- See :doc:`/gallery/color/colormap_reference` for a list of builtin
Copy link
Member

Choose a reason for hiding this comment

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

Don't indent bullet points. RestructuredText interprets this as a blockquote. This leads to over-indented bullet points in the HTML.

grafik

Copy link
Member Author

Choose a reason for hiding this comment

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

No problem - shoudl this be a seealso::?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, you could make this a seealso::.

If you switch to seealso:: the following is just for information: Make sure to write bullet lists exactly like this:

    Some paragraph:

    - Some long text that is continued on
      the next line.
    - Some other text.

    Normal paragraph again.
  1. No indent of the bullets with respect to the surronding paragraphs (that's fixed now).
  2. Continued bulleted lines have to have the text alinged with the text after the bullet (you had extra indentation here.
  3. There needs to be an empty line before and after the bullet list.

I know this is a bit picky, but that's how restructered text wants it.

plot_examples([viridis, newcmp])

##############################################################################
# LinearSegmented colormaps
Copy link
Member

Choose a reason for hiding this comment

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

  1. Would call this "Creating a new LinearSegmentedColormap" in resemblence to "Creating a new ListedColormap".

  2. Not sure if we need the "new" in the title.

Copy link
Member Author

Choose a reason for hiding this comment

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

Retitled

# LinearSegmented colormaps
# =========================
#
# `.LinearSegmentedColormap` have an alternate way to specify colormaps that
Copy link
Member

Choose a reason for hiding this comment

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

Alternative wording:

LinearSegmentedColormap specifies the colors using anchor points. The RGB(A) color values for positions in between the anchor points are linearly interpolated from the anchor point RGB(A) values.

Copy link
Member Author

Choose a reason for hiding this comment

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

rewritten...

# (RGBA).
#
# The format to specify these colormaps is a bit complicated to allow
# discontinuities at the anchor points. First, with no discontinuities:
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 the format needs a description here, or at least a "See LinearSegmentedColormap for a description of the format."

Copy link
Member Author

Choose a reason for hiding this comment

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

new version describes the format.

@jklymak jklymak force-pushed the doc-add-colormap-manipulation branch 2 times, most recently from 76b263c to 04e096f Compare August 24, 2018 17:42
@jklymak jklymak force-pushed the doc-add-colormap-manipulation branch 7 times, most recently from 4302477 to e76b41b Compare August 24, 2018 20:53
@jklymak
Copy link
Member Author

jklymak commented Aug 24, 2018

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

The LinearSegmented color map is much cleaner now.

Good to go after the bullet list/seealso in cm.py is fixed.

plot_examples([viridis, newcmp])

##############################################################################
# Creating LinearSegmented colormaps
Copy link
Member

Choose a reason for hiding this comment

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

I would either use the class name "Creating LinearSegmentedColormaps" or a textual description "Creating linear segmented colormaps" (or maybe "Creating linear-segmented colormaps" I'm never sure when to use a hyphen). In any case no mixture.

Same with "Creating listed colormaps".

Copy link
Member Author

Choose a reason for hiding this comment

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

Now

  • Creating listed colormaps
  • Creating linear segmented colormaps

@jklymak jklymak force-pushed the doc-add-colormap-manipulation branch from e76b41b to 84e9f62 Compare August 24, 2018 22:23
@jklymak jklymak force-pushed the doc-add-colormap-manipulation branch from 84e9f62 to e9cda7f Compare August 24, 2018 22:32
@jklymak jklymak removed the request for review from afvincent August 24, 2018 23:28
@timhoffm timhoffm merged commit b02c22d into matplotlib:master Aug 25, 2018
@lumberbot-app
Copy link

lumberbot-app bot commented Aug 25, 2018

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v2.2.3-doc
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 b02c22dcdcda8931f00b14da2ad8a3d7356c55d8
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #11905: DOC: colormap-manipulation tutorial'
  1. Push to a named branch :
git push YOURFORK v2.2.3-doc:auto-backport-of-pr-11905-on-v2.2.3-doc
  1. Create a PR against branch v2.2.3-doc, I would have named this PR:

"Backport PR #11905 on branch v2.2.3-doc"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

@timhoffm
Copy link
Member

Thanks! This is a significant improvement on the documentation of colormaps.

@tacaswell tacaswell modified the milestones: v2.2-doc, v3.0.2 Nov 10, 2018
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Nov 10, 2018
…ipulation

DOC: colormap-manipulation tutorial
@tacaswell tacaswell mentioned this pull request Nov 10, 2018
tacaswell added a commit that referenced this pull request Nov 10, 2018
DOC: Backport colormap documentation

Includes  #11905, #11799, #11881, and #12084
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: Colormap tutorial needs info on manipulating colormaps
4 participants