Marsilea-viz / marsilea

Declarative creation of composable visualization for Python (Complex heatmap, Upset plot, Oncoprint and more~)
https://marsilea.rtfd.io/
MIT License
166 stars 6 forks source link

AttributeError: 'Marker' object has no attribute 'marker' #31

Closed aadimator closed 6 months ago

aadimator commented 6 months ago

I'm getting the following error when I try to add legends to Marker object:

sig_plot = ma.Layers(data=data, pieces=mapper)
sig_plot.add_left(mp.Labels(kim_sign_sc.columns, rotation=0, padding=5))
sig_plot.add_legends()
sig_plot.render()
File [c:\Users\mraadam\AppData\Local\miniforge3\envs\pdac_nac\lib\site-packages\marsilea\layers.py:379](file:///C:/Users/mraadam/AppData/Local/miniforge3/envs/pdac_nac/lib/site-packages/marsilea/layers.py:379), in Marker.legend(self, x, y, w, h)
    [377](file:///C:/Users/mraadam/AppData/Local/miniforge3/envs/pdac_nac/lib/site-packages/marsilea/layers.py:377) def legend(self, x, y, w, h):
    [378](file:///C:/Users/mraadam/AppData/Local/miniforge3/envs/pdac_nac/lib/site-packages/marsilea/layers.py:378)     return Line2D(
--> [379](file:///C:/Users/mraadam/AppData/Local/miniforge3/envs/pdac_nac/lib/site-packages/marsilea/layers.py:379)         [0], [0], marker=self.marker, color=self.color, markersize=self.size
    [380](file:///C:/Users/mraadam/AppData/Local/miniforge3/envs/pdac_nac/lib/site-packages/marsilea/layers.py:380)     )

I think the problem is because in the legend function of the Marker class, we are accessing self.marker but we haven't assigned it in the init step:

class Marker(Piece):
    def __init__(self, marker, color="C0", size=32, label=None, legend=True, zorder=0):
        self.color = color
        self.label = label
        self.legend_entry = legend
        self.zorder = zorder
        self.size = size
        m = MarkerStyle(marker)
        self.path = m.get_path().transformed(m.get_transform())

    def draw(self, x, y, w, h, ax):
        c = self.draw_center(x, y, w, h)
        collection = PathCollection(
            (self.path,),
            [self.size],
            offsets=[c],
            offset_transform=ax.transData,
            facecolors=self.color,
        )
        collection.set_transform(IdentityTransform())

        return collection

    def legend(self, x, y, w, h):
        return Line2D(
            [0], [0], marker=self.marker, color=self.color, markersize=self.size
        )
Mr-Milk commented 6 months ago

Thank you for reporting this bug, this will be fixed in next release.