You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is an implementation I came up with, which is based on geom_point. I have been using this for months now for .png files. A drawback is that draw_panel directly calls draw_unit. I couldn't make it work with draw_group. Maybe it isn't necessary.
@documentclassgeom_image(geom):
""" Plot Images with plotnine Based on geom_point Instead of points, plots images at those points Args: geom : ggplot geom """DEFAULT_AES= {"size": 0.1}#, "color": None, "fill": "#333333",#"linetype": "solid", "size": 0.5 }DEFAULT_PARAMS= {"stat": "identity", "position": "identity",
"na_rm": False} # no idea if I need thisREQUIRED_AES= {"x", "y","image"} # just need an image columndefdraw_panel(self, data, panel_params, coord, ax, **params):
""" assume only one image per panel, """data=coord.transform(data, panel_params)
self.draw_unit(data, panel_params, coord, ax, **params)
@staticmethoddefdraw_group(data, panel_params, coord, ax, **params):
data=coord.transform(data, panel_params)
units="shape"for_, udataindata.groupby(units, dropna=False):
udata.reset_index(inplace=True, drop=True)
geom_image.draw_unit(udata, panel_params, coord, ax, **params)
@staticmethoddefdraw_unit(data, panel_params, coord, ax, **params):
foriinrange(len(data)):
img=data["image"].iloc[i]
zoom=data["size"].iloc[i]
ab=AnnotationBbox(
OffsetImage(plt.imread(img), zoom=zoom),
(data["x"].iloc[i], data["y"].iloc[i]),
frameon=False,
)
ax.add_artist(ab)
I would appreciate something like geom_image -library(ggimage)-
https://github.com/GuangchuangYu/ggimage
for plotnine.
geom_image allows to place an image at aes(x,y)
Not difficult to achieve? Here is an example using plt:
https://github.com/TerryGamon/Chess4Python
drawPosition("r1b1k1nr/p2p1pNp/n2B4/1p1NP2P/6P1/3P1Q2/P1P1K3/q5b1")
The text was updated successfully, but these errors were encountered: