I have a boxplot and need to remove the x-axis ('user_type' and 'member_gender') label. How do I do this given the below format?
sb.boxplot(x="user_type", y="Seconds", data=df, color = default_color, ax = ax[0,0], sym='').set_title('User-Type (0=Non-Subscriber, 1=Subscriber)')
sb.boxplot(x="member_gender", y="Seconds", data=df, color = default_color, ax = ax[1,0], sym='').set_title('Gender (0=Male, 1=Female, 2=Other)')
Matplotlib removes both labels and ticks by using xaxis. set_visible() set_visible() method removes axis ticks, axis tick labels, and axis labels also. It makes the axis invisible completely.
We can turn off X-axis by passing False as an argument to get_xaxis(). set_visible() . And to turn off Y-axis we pass False as an argument to get_yaxis(). set_visible() .
To change the position of the labels, in the Axis labels box, click the option that you want. Tip To hide tick marks or tick-mark labels, in the Axis labels box, click None.
To remove X or Y labels from a Seaborn heatmap, we can use yticklabel=False.
.set()
..set(xticklabels=[])
should remove tick labels.
.set_title()
, but you can use .set(title='')
..set(xlabel=None)
should remove the axis label..tick_params(bottom=False)
will remove the ticks.fig, ax = plt.subplots(2, 1)
g1 = sb.boxplot(x="user_type", y="Seconds", data=df, color = default_color, ax = ax[0], sym='')
g1.set(xticklabels=[])
g1.set(title='User-Type (0=Non-Subscriber, 1=Subscriber)')
g1.set(xlabel=None)
g2 = sb.boxplot(x="member_gender", y="Seconds", data=df, color = default_color, ax = ax[1], sym='')
g2.set(xticklabels=[])
g2.set(title='Gender (0=Male, 1=Female, 2=Other)')
g2.set(xlabel=None)
import seaborn as sns
import matplotlib.pyplot as plt
# load data
exercise = sns.load_dataset('exercise')
pen = sns.load_dataset('penguins')
# create figures
fig, ax = plt.subplots(2, 1, figsize=(8, 8))
# plot data
g1 = sns.boxplot(x='time', y='pulse', hue='kind', data=exercise, ax=ax[0])
g2 = sns.boxplot(x='species', y='body_mass_g', hue='sex', data=pen, ax=ax[1])
plt.show()
fig, ax = plt.subplots(2, 1, figsize=(8, 8))
g1 = sns.boxplot(x='time', y='pulse', hue='kind', data=exercise, ax=ax[0])
g1.set(xticklabels=[]) # remove the tick labels
g1.set(title='Exercise: Pulse by Time for Exercise Type') # add a title
g1.set(xlabel=None) # remove the axis label
g2 = sns.boxplot(x='species', y='body_mass_g', hue='sex', data=pen, ax=ax[1])
g2.set(xticklabels=[])
g2.set(title='Penguins: Body Mass by Species for Gender')
g2.set(xlabel=None)
g2.tick_params(bottom=False) # remove the ticks
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With