-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Adds function to sample colorscales #3136
Adds function to sample colorscales #3136
Conversation
Thank you! We will be doing some work in this library in the coming weeks to prepare for the 5.0 release and I will take a closer look at this PR then :) |
if colorscale in PLOTLY_SCALES: | ||
colorscale = PLOTLY_SCALES[colorscale] | ||
else: | ||
raise exceptions.PlotlyError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand this error message... Under what circumstances would we accept "an rgb color or a hex color" here?
Interpolates between colors in a colorscale to find the specific colors | ||
corresponding to the specified sample values. The colorscale can be specified | ||
as a list of `[scale, color]` pairs, as a list of colors, or as a named | ||
plotly colorscale. The samplepoints can be specefies an iterable of specific |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here: "specefies an"
This is a pretty great little function that really reuses a bunch of built-in logic, thanks so much! I've left a couple of comments and if you could please merge master into this branch or rebase it on top of master, I think we can merge it in without too much fuss. It might be nice to add a test? |
Note to self: this new function needs to be added to the |
A typo in the docstring and a confusing error message.
A simple test that checks the consistency of sampling a colorscale on the actual definition points, as well as sampling a very simple scale at simple points.
Had some issues with running black locally due to version problems. Now resolved and formatted the test code accordingly :)
Thanks for the changes! In addition to my comment here #3185 (comment) about further work that could be done in this PR, I also had the idea that it might be possible to dynamically attach this function to objects like |
I would love to have colorscale sampling available with that kind of syntax! However, since the colorscales are stored as plain python lists, we cannot attach new attributes to them... This would mean that we have to wrap the colorscales in a new class, which would open the opportunity to attach a lot more functionality to a colorscale, and an overall more object oriented approach to the entire colors module. An interesting project, but perhaps a bit too much for this PR... |
Yep, just wanted to record it somewhere :) |
OK so I've merged #3186. If you want to merge that into this PR and use it in the new function, I'll merge this in today :) |
# Conflicts: # packages/python/plotly/_plotly_utils/colors/__init__.py # packages/python/plotly/plotly/tests/test_core/test_colors/test_colors.py
Thanks very much! |
Addition to the colors module which can sample a colorscale at arbitrary or equally spaced points.
Solves #2484.
Code PR
plotly.graph_objects
, my modifications concern thecodegen
files and not generated files.modified existing tests.
new tutorial notebook (please see the doc checklist as well).