0

I want to use datashader output as an input into a plt subplot.

I am trying to run the code suggested in the answer to this question: Add datashader image to matplotlib subplots

Here is the code below:

from datashader.mpl_ext import DSArtist
import datashader as ds
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import pandas as pd
import numpy as np

N = 10000
df = pd.DataFrame(np.random.random((N, 3)), columns = ['x','y', 'z'])

f, ax = plt.subplots(2, 2)
ax_r = ax.ravel()

da = DSArtist(ax_r[0], df, 'x', 'y', ds.mean('z'), norm = mcolors.LogNorm())
ax_r[0].add_artist(da)

ax_r[1].hist(df['x'])
ax_r[2].hist(df['y'])
ax_r[3].plot(df['z'])

plt.tight_layout()
plt.show()

I get an error:

---> da = DSArtist(ax_r[0], df, 'x', 'y', ds.mean('z'), norm = mcolors.LogNorm()) 
TypeError: __init__() missing 7 required positional arguments: 'shade_hook', 'plot_width', 'plot_height', 'x_range', 'y_range', 'width_scale', and 'height_scale'

I tried looking at source code of DSArtist here (https://github.com/holoviz/datashader/pull/200/files) but don't quite follow it.

How to resolve the error?

Thanks!

  • That PR is now outdated, because Datashader 0.12 includes native Matplotlib support; see https://datashader.org/getting_started/Interactivity.html#Native-support-for-Matplotlib . As of 1/2021 the plots there aren't rendered on the website, but they do work when run locally! – James A. Bednar Jan 16 '21 at 22:30
  • Thank you, it works @JamesA.Bednar – neurocaience Jan 19 '21 at 15:25
  • Great! If you get a chance, please answer your own question with the updated code that works for you now, as a guide for others. – James A. Bednar Jan 20 '21 at 16:44

0 Answers0