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

`cut_rows` affects the color of `mp.Numbers` #43

Closed SunYong0821 closed 1 month ago

SunYong0821 commented 1 month ago

if I didnt use cut_rows:

sb = mp.StackBar(t_p*100, colors=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#c49c94', '#f7b6d2', '#c7c7c7', '#dbdb8d', '#9edae5'], width=.8, orient="h")
gc_numbers = mp.Numbers(group_count, color=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#c49c94', '#f7b6d2', '#c7c7c7', '#dbdb8d', '#9edae5'])
cb = ma.ClusterBoard(t_p.T, height=4, margin=.5)
cb.add_layer(sb)
cb.add_right(gc_numbers, size=1.1, pad=.25)
cb.render()

微信截图_20240905091327

if i use cut_rows:

sb = mp.StackBar(t_p*100, colors=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#c49c94', '#f7b6d2', '#c7c7c7', '#dbdb8d', '#9edae5'], width=.8, orient="h")
gc_numbers = mp.Numbers(group_count, color=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#c49c94', '#f7b6d2', '#c7c7c7', '#dbdb8d', '#9edae5'])
cb = ma.ClusterBoard(t_p.T, height=4, margin=.5)
cb.add_layer(sb)
cb.add_right(gc_numbers, size=1.1, pad=.25)
cb.cut_rows([4,7,9], spacing=.03)
cb.render()

微信截图_20240905091408

why?

Mr-Milk commented 1 month ago

The color parameter in Numbers is designed to accept only a single color as indicated in the documentation. Although it works if you supply multiple colors, the behavior is not guaranteed. If you want to customize each color, please use Bar and check the last example https://marsilea.readthedocs.io/en/stable/api/APIs/marsilea.plotter.Bar.html

SunYong0821 commented 1 month ago

The color parameter in Numbers is designed to accept only a single color as indicated in the documentation. Although it works if you supply multiple colors, the behavior is not guaranteed. If you want to customize each color, please use Bar and check the last example https://marsilea.readthedocs.io/en/stable/api/APIs/marsilea.plotter.Bar.html`Numbers`中的`color`参数设计为仅接受文档中指示的单一颜色。虽然如果您提供多种颜色它可以工作,但不能保证其行为。如果您想自定义每种颜色,请使用`Bar`并检查最后一个示例https://marsilea.readthedocs.io/en/stable/api/APIs/marsilea.plotter.Bar.html

It seems that it's not quite working either. 微信截图_20240905135513

SunYong0821 commented 1 month ago

The color parameter in Numbers is designed to accept only a single color as indicated in the documentation. Although it works if you supply multiple colors, the behavior is not guaranteed. If you want to customize each color, please use Bar and check the last example https://marsilea.readthedocs.io/en/stable/api/APIs/marsilea.plotter.Bar.html

group_rows, cut_rows and hsplit,It appears that these three features seem identical, but do they have any differences?

Mr-Milk commented 1 month ago

This is what you want:

import marsilea as ma
import marsilea.plotter as mp
import numpy as np

data = np.random.randn(4, 4)

h = ma.Heatmap(data)
h.add_right(mp.Bar([1,2,3,4], palette=["r", "g", ".1", ".8"]))
h.cut_rows([2])
h.render()

image

Mr-Milk commented 1 month ago

The color parameter in Numbers is designed to accept only a single color as indicated in the documentation. Although it works if you supply multiple colors, the behavior is not guaranteed. If you want to customize each color, please use Bar and check the last example https://marsilea.readthedocs.io/en/stable/api/APIs/marsilea.plotter.Bar.html

group_rows, cut_rows and hsplit,It appears that these three features seem identical, but do they have any differences?

Regarding this, hsplit and vsplit are deprecated, you should see a warning when you use them. group_rows can split by given labels and order, cut_rows can split only by the index of row.

Mr-Milk commented 1 month ago

@SunYong0821 As of v0.4.6, you can use multiple colors for color in Numbers.

Hope you enjoy Marsilea!

import marsilea as ma
import marsilea.plotter as mp
import numpy as np

data = np.random.randn(4, 4)

h = ma.Heatmap(data)
h.add_right(mp.Numbers([1, 2, 3, 4], color=["r", "g", ".1", ".8"]))
h.cut_rows([2])
h.render()

image

SunYong0821 commented 1 month ago

The color parameter in Numbers is designed to accept only a single color as indicated in the documentation. Although it works if you supply multiple colors, the behavior is not guaranteed. If you want to customize each color, please use Bar and check the last example https://marsilea.readthedocs.io/en/stable/api/APIs/marsilea.plotter.Bar.html`Numbers`中的`color`参数设计为仅接受文档中指示的单一颜色。虽然如果您提供多种颜色它可以工作,但不能保证其行为。如果您想自定义每种颜色,请使用`Bar`并检查最后一个示例https://marsilea.readthedocs.io/en/stable/api/APIs/marsilea.plotter.Bar.html

group_rows, cut_rows and hsplit,It appears that these three features seem identical, but do they have any differences?group_rows、cut_rows 和 hsplit,看起来这三个功能看起来相同,但是它们有什么区别吗?

Regarding this, hsplit and vsplit are deprecated, you should see a warning when you use them. group_rows can split by given labels and order, cut_rows can split only by the index of row.关于这一点, hsplitvsplit已被弃用,您在使用它们时应该会看到警告。 group_rows可以按给定的标签和顺序进行拆分, cut_rows只能按行的索引进行拆分。

OK thx

SunYong0821 commented 1 month ago

@SunYong0821 As of v0.4.6, you can use multiple colors for color in Numbers.

Hope you enjoy Marsilea!

import marsilea as ma
import marsilea.plotter as mp
import numpy as np

data = np.random.randn(4, 4)

h = ma.Heatmap(data)
h.add_right(mp.Numbers([1, 2, 3, 4], color=["r", "g", ".1", ".8"]))
h.cut_rows([2])
h.render()

image

I test it pefect!~ thx~ 微信截图_20240909104930