How can one export a datashader image to a png file?
1 Like
import datashader as ds
import datashader.transfer_functions as tf
from datashader.utils import export_image
from functools import partial
from datashader.colors import colormap_select
from colorcet import fire
# plot via datashader
ds.transfer_functions.Image.border=0
background = "black"
cm = partial(colormap_select, reverse=(background!="black"))
export = partial(export_image, background = background, export_path="img")
cvs = ds.Canvas(plot_width=700, plot_height=700)
agg = cvs.points(df, "x", "y")
img = tf.shade(agg, cmap = cm(fire,0.2), how='linear')
export(img, "out")
1 Like
That version has a lot of complexity only needed for the Census example. General usage would be something like:
import datashader as ds, pandas as pd
from datashader.utils import export_image
from colorcet import fire
df = ...
cvs = ds.Canvas(plot_width=700, plot_height=700)
agg = cvs.points(df, "x", "y")
img = ds.tf.shade(agg, cmap=fire, how='linear')
export_image(img, "out", background="black", export_path=".")
2 Likes
Hi!..I’m trying to save an image as PNG/PDF/SVG format from datashader. I’m working on Google colab.
This is the code and the error I get when trying pillow:
cvs = ds.Canvas(plot_width = 700, plot_height = 700)
agg = cvs.points(df, ‘x’, ‘y’)
ds.transfer_functions.Image.border=0
imagen=bg(tf.shade(agg, cmap = inferno))
!pip install pillow
imagen2=plot.to_pil(imagen)
imagen2.save(‘model300dpi.png’, dpi=(300,300))
What an I doing wrong?