Marsilea-viz/marsilea

Ability to flip the Numbers plot

Closed this issue · 2 comments

Let's take the example plot here:
image

Let's say I want to create a Numbers plot that looks like the CenterBar plot in the image above. I can create one Numbers plot, add at it to the right of main canvas layer, but I don't know how I can include another one and flip it so it looks like the CenterBar above. I tried using the CenterBar but it makes the axes of both values the same, i.e. let's say one data column has values ranging from 2000 to 20,000, while the other one has 0 to 10. CenterBar would make both axes 0 to 20,000. I wasn't able to figure out how to change the axes of the second part.

The idea of CenterBar is to make two datasets comparable, if you use different scales, the comparison would be unfair.

However, you can create your own CenterBar, you may refer to this part of the documentation on how to implement a custom plotter: https://marsilea.readthedocs.io/en/latest/tutorial/new_renderplan.html

A slight modification to the code of CenterBar to have your own plotter is a quick way to go.

I was able to hack something together by doing this:

sample_patient = mp.Numbers(
   data, label='No. of Samples', show_value=False, color='#F5E9CF'
)
cb.add_right(sample_patient, pad=0.2, name='samples')
samples_axes = cb.get_ax('samples')
for ax in samples_axes:
    ax.invert_xaxis()
    ax.bar_label(ax.containers[0], fmt=fmt, padding=3)

Posting here so someone (or myself 🙄) in the future can get some idea from this.