-
-
Notifications
You must be signed in to change notification settings - Fork 14
Adding a Gradient Background to HorizonPlots #155
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
base: develop
Are you sure you want to change the base?
Adding a Gradient Background to HorizonPlots #155
Conversation
…lours. Colour presets can be called from the yaml file with extensions.GRADIENTS[<preset name>].
… This adds a vertical colour gradient to the background of the plot. e.g. to simulate twilight lighting in the sky. The function takes the bounds of the figure's axes, creates a set of background axes, creates a colourmap and adds it to the background axes using imshow(). Added an if loop to _init_plot() so that _apply_gradient_background() is applied if a color_stop list is provided when HorizonPlot is instantiated.
There are six presets in total. Each preset contains a range of colours and each colour is listed with its position in the gradient.
…a horizon map looking south from Stonehaugh, England.
… in horizon_gradient.py
… file and moves it to the horizon-gradient.md file.
…ssing commas, mixed "", and extra newlines.
@Niphredil123 Amazing, thanks so much for this contribution!! I've been wanting to add this to Starplot for awhile now, and your example image looks great! And I love that you added those six different gradient definitions. Give me a few days to review this a little (I'm out of town right now), but one thing I'm curious about is if you got those gradients from some known source? Just wanna make sure we can include them as part of the starplot code and if they're from some open source project I'd like to add some reference to it. Oh, also, I noticed you linked to the Notion roadmap, but we've moved over to Trello because they have a nicer free plan. I thought I updated all the docs to Trello, but maybe I missed a spot? Wondering where you got the notion link? Was it a previous version's docs? And, thanks for following the contributor's guide and merging to the Thanks again! :) Steve |
@steveberardi I'm glad, you like it! It was a fun challenge to figure out. No rush with the review :) For the colours, I looked at night sky colour palettes on Google images for inspiration and then used MakeGradients.app to design my own. That is also what I used to generated the little example squares. From their FAQs: "All gradients you create can be freely used in personal or commercial projects with no restrictions or attributions needed." The only palette I actually used any hex codes from was number 19 from this Creative Booster inspiration post. I used their hex codes for magenta (#932885) and orange (#FFAF36) in I found the Notion board in the contributing doc. I did find the Trello board later, but referenced the Notion board becuase that was where the gradients were specifically mentioned. Hope it all runs smoothly when you check it :) |
I finally had a chance to start looking at the code here, and try running it, and noticed a few things so far:
Would you be interested in helping explore solutions to any of the above? If not, no worries, I can also merge this PR as-is and work on them. Also, thanks so much for taking the time to read the Starplot code and following so many of the current patterns in the code! 😃 |
…_background(). This improves gradient smoothness. Minimised the size of the gradient array in the same function to improve efficiency.
I'd be delighted to help explore solutions to the points you've listed, and anything else that comes up.
Your other points sounds really good and I'd be happy to work towards them after invesitgating the code segements a bit more. |
@Niphredil123 Great! One thing that might help with comparing runtimes of different gradient rendering methods is enabling "debug" mode on the plots. If you pass You can also add another function to that debug output by using the profile decorator. One last thing that would be great to add for this is a "hash check". More info here, but let me know if any of that is unclear. The hash check stuff might have some difficulty with the gradients, so if you add a check and it's flaky (passes sometimes, fails other times) then one thing that might help avoid that is dramatically simplifying the gradient map (e.g. just one stop at 50% instead of 10 stops). Thanks!! I think starplot users are gonna love this feature! |
also, I totally forgot to mention a |
- Used pcolormesh instead of imshow to plot the gradient as this drastically improved export time. - Changed how set self.ax.zorder was set to improve export time. - Discovered that changing the altitude caused unexpected axes mis-alignment so added an event driven function such that the gradient background axes now resize with the main axes when it is drawn.
…ection of using cmaps. Changed shade of orange in nautical_twilight to make it softer.
…d to horizon_checks.py. Added the hashes for the new image to the hashlock.yml file.
awesome!! 🎉
Also awesome! I'm hoping to include this as a major feature of the 0.16 release 😃 |
Inspired by this Horizon Plot task in the Notion roadmap, I have worked to add the ability to add a gradient background to horizon plots.
Key Actions
_apply_gradient_background()
to the HorizonPlot class inhorizon.py
.imshow()
._init_plot()
in the HorizonPlot class such that_apply_gradient_background()
is applied if agradient_preset
parameter is provided when HorizonPlot is instantiated.styles/ext/gradient_presets.yml
, containing six pre-set gradient colour gradient lists.GRADIENTS
tostyles/extensions.py
so presets can be set usingextensions.GRADIENTS["<preset name>"]
.Additional Actions
examples/horizon_gradient.py
containing an example horizon plot with a gradient.docs/examples/horizon-gradient.md
to list the example horizon gradient plot inhorizon_gradient.py
.docs/examples.md
.Adding a Gradient to a HorizonPlot
To create a HorizonPlot with a gradient, one includes the parameter
gradient_preset
when instansiatingHorizonPlot
. This can be done in two ways:OR
When adding the parameter as a list, the position values must range from 0-1.
Note that
backgound_color
must be set as transparent using a hex with alpha string (e.g.#ffffff00
) when extending thePlotStyle()
. This is because the gradient is plotted under the starplot plot, so will not be visible if the background is not transparent.Images
Below are the images I make reference to in
docs/examples/horizon-gradient.md
(first two) anddocs/example.md
(last one).