forked from scverse/spatialdata-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
43 lines (32 loc) · 1.29 KB
/
basic.py
File metadata and controls
43 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import numpy as np
from matplotlib import pyplot as plt
from ..accessor import register_spatial_data_accessor
@register_spatial_data_accessor("pl")
class PlotAccessor:
def __init__(self, sdata):
self._sdata = sdata
def imshow(self, ax=None, ncols=4, width=4, height=3, **kwargs):
image_data = self._sdata.images
num_images = len(image_data)
if num_images == 1:
ax = ax or plt.gca()
key = [k for k in image_data.keys()][0]
ax.imshow(image_data[key].values.T)
ax.set_title(key)
else:
nrows, reminder = divmod(num_images, ncols)
if reminder > 0:
nrows += 1
fig, axes = plt.subplots(nrows, ncols, figsize=(ncols * width, nrows * height))
for i, (ax, (k, v)) in enumerate(zip(np.ravel(axes), image_data.items())):
if i < num_images:
ax.imshow(v.values.T)
ax.set_title(k)
# get rid of the empty axes
for i in range(num_images, ncols * nrows):
axes.ravel()[i].axis("off")
return self._sdata
def test_plot(self):
plt.plot(np.arange(10), np.arange(10))
def scatter(self):
plt.scatter(np.random.randn(20), np.random.randn(20))