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

How to display the x-axis label in a stacked bar chart? #40

Closed z626093820 closed 2 months ago

z626093820 commented 2 months ago

from marsilea.plotter import StackBar import numpy as np import pandas as pd import matplotlib.pyplot as plt

_, ax2 = plt.subplots() StackBar(dfbar2,show_value=True).render(ax2)

image

How to display the x-axis label in a stacked bar chart? THANK YOU! such as blew image

Mr-Milk commented 2 months ago

Hi, thanks for using Marsilea.

Most of the time you don't need to touch matplotlib APIs in Marsilea. You always initiate a canvas object in Marsilea and then add things on top of it. This will give you much more flexible controls, you can add the labels on either the bottom or top, and you can easily control the size and padding of all your plotters. Hope you have fun using Marsilea!

import numpy as np
import pandas as pd

import marsilea as ma
import marsilea.plotter as mp

data = np.random.randint(1, 10, (10, 10))
labels = [f"Label_{i+1}" for i in range(10)]

b = ma.WhiteBoard(width=8)
b.add_layer(mp.StackBar(pd.DataFrame(data)))
b.add_bottom(mp.Labels(labels, rotation=0), pad=.1)
b.add_top(mp.Labels(labels, rotation=0), pad=.1)
b.render()

image

z626093820 commented 2 months ago

Hi, thanks for using Marsilea.

Most of the time you don't need to touch matplotlib APIs in Marsilea. You always initiate a canvas object in Marsilea and then add things on top of it. This will give you much more flexible controls, you can add the labels on either the bottom or top, and you can easily control the size and padding of all your plotters. Hope you have fun using Marsilea!

import numpy as np
import pandas as pd

import marsilea as ma
import marsilea.plotter as mp

data = np.random.randint(1, 10, (10, 10))
labels = [f"Label_{i+1}" for i in range(10)]

b = ma.WhiteBoard(width=8)
b.add_layer(mp.StackBar(pd.DataFrame(data)))
b.add_bottom(mp.Labels(labels, rotation=0), pad=.1)
b.add_top(mp.Labels(labels, rotation=0), pad=.1)
b.render()

image

THANK YOU!