Seaborn Jointplot Change Figsize [duplicate] - python

This question already has answers here:
How to plot non-square Seaborn jointplot or JointGrid
(3 answers)
Closed 3 years ago.
I am using Jupyter Notebook and want a full width jointplot figure.
I cant seem to get it working though.
g = sns.jointplot(x="pos", y="diff", data=plot_data)
plt.figure(figsize=(16, 6))
doesn't change the size at all.
fig, ax = plt.subplots(figsize=(16, 6))
g = sns.jointplot(ax=ax, x="pos", y="diff", data=plot_data)
Throws an error.

Use the height parameter in the jointplot function to set the size of the figure(it will be square). Refer to official docs: seaborn.pydata.org/generated/seaborn.jointplot.html

Related

seaborn.lmplot with single axes labels [duplicate]

This question already has answers here:
Python Seaborn Facetgrid change xlabels
(2 answers)
Common xlabel/ylabel for matplotlib subplots
(8 answers)
How to add a shared x-label and y-label to a plot created with pandas plot
(4 answers)
One shared x-axis label for Seaborn FacetGrid subplots (layouts/spacing?)
(1 answer)
How to set common axes labels for subplots
(9 answers)
Closed last year.
What I need should be straighforward but I couldn't find a solution. Say we draw the following seaborn.lmplot:
import seaborn as sns; sns.set_theme(color_codes=True)
tips = sns.load_dataset("tips")
g = sns.lmplot(x="total_bill", y="tip", col="day", hue="day",
data=tips, col_wrap=2, height=3)
I simply want to have a single label for the x-axis and a single label for the y-axis instead of two as currently.
In other words, that the word 'tip' be printed only one time on the centre left of the graph, and that the word 'total_bill' be printed only one time on the bottom centre of the graph.
How do we do this?
EDIT: there is a similar question here One shared x-axis label for Seaborn FacetGrid subplots (layouts/spacing?) yet it is not elaborated and does not solve my issue.

How to add displot to sub-histogram using matplotlib [duplicate]

This question already has answers here:
Add density curve on the histogram
(2 answers)
Closed 8 months ago.
I have simplified code like this:
fig, axs = plt.subplots(1, 2)
axs[0].hist(x)
axs[1].hist(y)
and I need to add density curve to each plot. Anyone know reasonable simple way to do this? It could be using seaborn. Kindly help.
Funtion seaborn.displot() does not working in subplots.
You could use seaborn.histplot and pass kde parameter:
fig, axs = plt.subplots(1, 2)
sns.histplot(x, ax = axs[0], kde = True)
sns.histplot(y, ax = axs[1], kde = True)

Legend of the graph was cut out while exporting via Matplotlib [duplicate]

This question already has answers here:
Moving matplotlib legend outside of the axis makes it cutoff by the figure box
(4 answers)
Closed 1 year ago.
I'm working with a matplotlib created multiline graph with such an external legend that extends outside the boundaries of the figure.
my code:
dataset = [1,2,3,4,5]
y_axis = np.arange(0,20,5)
plt.figure(figsize=(7,5))
A = [1,3,7,8,9]
B = [12,16,14,7,4]
C = [4,17,19,8,6]
plt.plot(dataset,A ,label='A',color='#FFC000',linewidth=3,marker='.',markersize=12,linestyle='-')
plt.plot(dataset,B,label='B',color='#0070C0',linewidth=3,marker='s',markersize=8,linestyle='-')
plt.plot(dataset,C,label='C',color='#404040',linewidth=3,marker='+',markersize=10,linestyle='-')
plt.xticks(dataset)
plt.yticks(y_axis)
plt.xlabel('JobID')
plt.ylabel('Profite')
axes = plt.gca()
axes.yaxis.grid()
plt.legend(bbox_to_anchor=(1.20, 0.6),loc='best')
plt.savefig('Figure.jpg',dpi=300)
files.download("Figure.jpg")
plt.show()
Unfortunately, the legend is chopped out of the exported image while the figure is downloaded using the savefig and download commands.
You can see the problem more clearly with this Colab Link (in the last cell).
Please suggest any solution to fix this out.
Use tight_layout:
# plt.legend(bbox_to_anchor=(1.20, 0.6),loc='best')
# plt.savefig('Figure.jpg',dpi=300)
plt.legend(bbox_to_anchor=(1.04,0.5), loc="center left", borderaxespad=0)
plt.tight_layout(rect=[0,0,0.95,1])
plt.savefig("output.png", bbox_inches="tight")

How to show colorbar on each individual matshow subplot [duplicate]

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!

labels dimension or rotate python seaborn graphs [duplicate]

This question already has answers here:
Rotate label text in seaborn factorplot
(10 answers)
Closed 6 years ago.
I would like to fix label problems in a seaborn graph, I have more than 30 items in the x axis. How to reduce the label dimension or may be rotate the graph?
import seaborn as sns
g = sns.factorplot(x="target", data=df3, kind="count",
palette="BuPu", size=6, aspect=1.5)
This will work if executed in a single cell in Jupyter:
g = sns.factorplot(x="target", data=df3, kind="count",
palette="BuPu", size=6, aspect=1.5)
g.set(xticks=np.arange(0, 40, 3)) # or however many you have
plt.xticks(rotation=90);
It will also work if executed as one block in Spyder.

Categories

Resources