This question already has answers here:
Rotating axis text for each subplot
(3 answers)
Date ticks and rotation in matplotlib
(6 answers)
Aligning rotated xticklabels with their respective xticks
(5 answers)
Closed 2 years ago.
I have subplots with shared x,y axis. The x-axis is datetime stamp. Everything looks fine. The problem is x-axis looks clumsy.
My code:
fig, ax = plt.subplots(nrows=rows, ncols=cols,sharey=True,sharex=True)
fig.subplots_adjust(hspace=0.025, wspace=0.05)
for i in range(rows):
for j in range(cols):
#### plot data goes here.
ax[i,j].autofmt_xdate()
ax[i,j].xaxis.set_tick_params(rotation = 30)
fig.subplots_adjust(right=0.95)
plt.show()
Present output: The x-axis labels look clumsy, hard to read.
Related
This question already has answers here:
matplotlib y-axis label on right side
(4 answers)
using pandas.DataFrame.melt() to plot data with seaborn
(1 answer)
seaborn multiple variables group bar plot
(1 answer)
Closed 8 months ago.
I have the chart below:
Almost everything is fine, except that I want to see the numbers close to the y axis on the right side of the chart.
They represent values that correspond to the labels on y axis as they are. I was thinking that maybe I could just do a mirror for the x axis for one of the plots, but not sure how to do it. Because if I do a mirror I end up doing it for everything.
My code is like that at the moment:
plt.figure(figsize=(12,10))
ax = sns.barplot(x='commission', y="market", hue="is_control", data= df_base.sort_values(by = dimension, ascending = False))
ax = sns.barplot(x="foods and goods", y="market", hue="is_control", data= df_base.sort_values(by = dimension, ascending = False))
plt.title("Treatment vs Control Group {}.".format(country), fontsize=14)
plt.xlabel('% of reduction', fontsize=10)
plt.ylabel('market', fontsize=10)
plt.tight_layout()
for i in ax.containers:
ax.bar_label(i,)
This question already has answers here:
Set xticklabels for all grids, for a plot created with seaborn catplot that uses col_wrap [duplicate]
(1 answer)
How to rotate xticklabels in a seaborn catplot
(2 answers)
subplotting with catplot
(1 answer)
How to remove xticks from a catplot when there's no associated data
(1 answer)
Closed 10 months ago.
I have below code with axes in rows but only the last axes shows the xticks while I want to show the xticks on on each Axes. Please someone help me with this and also guide me how to individually control all the elements of axes.
g = sns.catplot(data = df_full[df_full['Team'].isin(Test_playing_list)], x = 'Match_Year', #palette = sns.color_palette('Paired', 7),
y = 'Win_percent',kind = "bar", height=3, aspect=3, linewidth = 2, row = 'Team', orient="v", facet_kws={'sharey':False, 'sharex':False})
plt.xticks(rotation = 90)
#plt.grid()
plt.show
This question already has answers here:
Wrapping long y labels in matplotlib tight layout using setp
(2 answers)
How to wrap xtick labels in matplotlib? [duplicate]
(1 answer)
split tick labels or wrap tick labels [duplicate]
(1 answer)
Closed 1 year ago.
I am plotting some variables but the data labels are a bit long so they are overlapping. I would like them to be displayed in multiple lines. The code I am using is this:
lista = list(df['col'].unique())
sns.countplot(data = df,x = 'col').set_xticklabels( lista,wrap=True)
sns.despine()
plt.show()
Seaborn plot
This question already has answers here:
Aligning rotated xticklabels with their respective xticks
(5 answers)
Closed 3 years ago.
After rotating the x_label, it could not align with major ticks or bars.
Here is my code:
x = df3[df3['Database'] == 'aminoglycoside'].Resistance_gene
y = df3[df3['Database'] == 'aminoglycoside'].Percent
plt.figure(figsize=(30,15))
plt.xticks(fontsize=20,rotation=45)
plt.margins(0.05)
plt.subplots_adjust(bottom=0.15)
plt.bar(x,y,width=0.5)
You can use the horizontalalignment option and align the text to the right, e.g.
import matplotlib.pyplot as plt
plt.plot(range(5))
plt.xticks(range(5),['some','long','labels','even','very long ones'],rotation=45,fontsize=20,horizontalalignment='right')
plt.show()
and get this
This question already has answers here:
matplotlib colorbar in each subplot
(5 answers)
Closed 3 years ago.
I am creating a (10,7) subplot of multiple different gridded fields. The following code is what is being currently used:
fig, axes = plt.subplots(nrows=10, ncols=7, figsize=(18, 16), dpi= 100,
facecolor='w', edgecolor='k')
titles = ['Z1','Z2','Z3','ZDR1','ZDR2','ZDR3','Dist']
for i in range(0,10):
z = 1*10+i
for j in range(0,7):
aa = axes[i,j].matshow(alldata_sim[z,:,:,j], cmap='jet')
fig.colorbar(aa)
axes[0,j].set_title(titles[j])
axes[i,j].get_xaxis().set_visible(False)
axes[i,j].get_yaxis().set_ticks([])
axes[i,0].set_ylabel(allgauge_sim[z])
Which produces the following figure:
Figure1
The question is: how do I get the colorbars to be on the right-hand side of each respective individual subplot?
maybe try changing
fig.colorbar(aa)
to
fig.colorbar(aa,ax=axes[i,j])
Hope it helps!