Exporting to png from datashader

How can one export a datashader image to a png file?

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=".")
1 Like