question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to shade an image with quantile color scale?

See original GitHub issue

I’m trying to plot points with DataShader and want to render points with a quantile color scale. Would you please help me with it?

Data:

lon,lat,metric
30.771635, 108.353681, 34
30.765280, 108.351067, 85 

Code:

import datashader as ds
import datashader.transfer_functions as tf
import colormap_select from datashader.colors 

// shade image
cm = partial(colormap_select)
agg = cvs.points(df, lon, lat, ds.sum('metric'))
img = tf.shade(agg, cmap=cm(['green', 'yellow', 'red']), how='eq_hist')

My Goal [‘green’, ‘yellow’, ‘red’] represent a quantile scale of aggregation: [0, 33%, 66%, 100%] . In other words:

  • green color: min -> 33% * max
  • yellow color: 33% * max -> 66% * max
  • red color: 66% * max -> max

Is there a method to achieve this color scale? furthermore, is there a way to flexibly define color stops ([0, 33%, 66%, 100%]) ?

Thank you.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jbednarcommented, Mar 2, 2018

Your code above can be simplified to:

import datashader as ds
import datashader.transfer_functions as tf

agg = cvs.points(df, lon, lat, ds.sum('metric'))
img = tf.shade(agg, cmap=['green', 'yellow', 'red'], how='eq_hist')

And presumably you are asking to get rid of the interpolation between green, yellow, and red that your code will produce?

image

If so, you can do that by constructing a colormap that avoids interpolation:

image

But personally, I like the interpolated one better. 😃

0reactions
jbednarcommented, Jun 19, 2018

Glad you like our work! The example above is an adaptation and extension of my “census_gray_redhot1_eq_hist” example in http://datashader.org/topics/census.html. But that’s just one example buried deep in between a bunch of others, and I think colormap manipulations like that are worth addressing explicitly in the user manual so that more people realize what can be done.

We’re currently working on re-implementing datashader’s more advanced colormap features in Bokeh, and when we have that ready, we should include an overview in the manual of how to use colormapping to reveal your data flexibly and effectively, particularly in conjunction with the percentile interpretation of the results of eq_hist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to shade an image with quantile color scale? #566
I'm trying to plot points with DataShader and want to render points with a quantile color scale. Would you please help me with...
Read more >
How to choose an interpolation for your color scale
I have a lowest value and a highest value. Just give the lowest value the brightest color and the highest value the darkest...
Read more >
Add colours to the quantiles using ggplot - Stack Overflow
1 Answer 1 · Use unname(quantiles) for the breaks . Additionally I made use of scales::number for nice labels. · You could set...
Read more >
Draws an image plot with a legend strip for the color scale...
Draws an image plot with a legend strip for the color scale based on either a regular grid or a grid of quadrilaterals....
Read more >
"Coloring Maps" - roadtolarissa
This post describes several d3 quantitative scales - linear, quantize, quantile ... that the range is a color and has colorScale return lighter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found