jcmgray / cotengra

Hyper optimized contraction trees for large tensor networks and einsums
https://cotengra.readthedocs.io
Apache License 2.0
174 stars 32 forks source link

Allow colormap instances to plot functions #7

Closed emprice closed 3 years ago

emprice commented 3 years ago

Hi @jcmgray,

This is a completely frivolous request, but I really like using colormaps from the cmasher package, which provides way more colorblind-safe, publication-quality maps than matplotlib does natively. As written, your code expects strings and uses getattr to grab the associated colormap from mpl.cm. All this PR does is put in a check that the input is not a colormap already before attempting that (could also check that it's a string?), and otherwise uses the input as-is. (IMHO, the more Pythonic solution would be for matplotlib to understand both strings and cmaps passed with the cmap kwarg, but it does not.)

I did a quick check, and I'm pretty sure this does nothing to affect the old behavior, it just adds the effect I've described.

pep8speaks commented 3 years ago

Hello @emprice! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 456:80: E501 line too long (82 > 79 characters) Line 467:80: E501 line too long (82 > 79 characters)

jcmgray commented 3 years ago

LGTM. I knew about colorcet and cmocean but not cmasher - thanks.