How to show probability density for a KDE plot in Seaborn? [duplicate] - matplotlib

This question already has answers here:
Seaborn kde plot plotting probabilities instead of density (histplot without bars)
(1 answer)
Seaborn distplot y-axis normalisation wrong ticklabels
(1 answer)
How to normalize seaborn distplot?
(2 answers)
Why does the y-axis of my distplot contain values up to 150?
(1 answer)
Closed 17 hours ago.
I'd like to construct a univariate KDE plot using Seaborn. The x-axis is amygdala volume, and I would like the y-axis to display probability densities. But when I use seaborn's kdeplot method, it seems like it's returning the raw counts (as if it was a histogram) instead of the densities. How do I get it to show the densities?
I've tried looking for parameters to include, but nothing would help.
plt.figure(figsize=(15,8))
sns.kdeplot(data=n90pol, x='amygdala', bw_adjust=0.5)
plt.xlabel('Amygdala Volume', fontsize=16);
plt.ylabel('Density', fontsize=16);
plt.title('KDE plot of Amygdala Volume', fontsize=24)

Related

Adjust position of colorbar in Matplotlib subplots [duplicate]

This question already has answers here:
Python matplotlib - how to move colorbar without resizing the heatmap?
(1 answer)
Matplotlib: let color bar not affect size and proportions of the plot
(2 answers)
How do I maintain image size when using a colorbar?
(2 answers)
Adjusting subplots to make space for colorbar
(1 answer)
Closed last month.
The Plot I Want to Fix
I am trying to graph three graphs stacked on top of each other and for the most part it works fine.
However when I add a colorbar to the last spectogram plot it completely squishes the plot, making the overall figure ugly.... How do I fix this?
fig, ax = plt.subplots(3, sharex=True, figsize=(50, 10))
fig.suptitle('Test' + str("%03d" % (i,)) + '+ Noisereduce', fontsize=48)
ax[0].plot(time, raw, color='blue')
ax[0].plot(time, fltr, color='orange')
ax[0].set_title('Raw Signal')
ax[1].plot(time, fltr, color='orange')
ax[1].set_title('noisereduce (stationary filter)')
spect = ax[2].pcolormesh(t, f, 10*np.log10(Sxx), vmin=vmin, vmax=vmax, shading='gouraud')
ax[2].set(xlabel='Time [sec]', ylabel='Frequency [Hz]')
fig.colorbar(spect, ax=ax[2])
ax[2].set_title('noisereduce - spectogram (upper 67% of intensities)')
plt.show()

Plot data using facet-grid in seaborn [duplicate]

This question already has answers here:
How to change the number or rows and columns in my catplot
(2 answers)
Seaborn multiple barplots
(2 answers)
subplotting with catplot
(1 answer)
Closed 4 months ago.
I have this dataset table
And i want to plot profit made by different sub_category in different region.
now i am using this code to make a plot using seaborn
sns.barplot(data=sub_category_profit,x="sub_category",y="profit",hue="region")
I am getting a extreamly huge plot like this output
is there is any way i can get sub-plots of this like a facet-gird. Like subplots of different sub_category. I have used the facet grid function but it is the also not working properly.
g=sns.FacetGrid(data=sub_category_profit,col="sub_category")
g.map(sns.barplot(data=sub_category_profit,x="region",y="profit"))
I am getting the following output
As you can see in the facet grid output the plots are very small and the bar graph is just present on one grid.
See docs on seaborn.FacetGrid, particularly the posted example, where you should not pass the data again in the map call but simply the plot function and x and y variables to draw plots to corresponding facets.
Also, consider the col_wrap argument since you do not specify row to avoid the very wide plot output.
g=sns.FacetGrid(data=sub_category_profit, col="sub_category", col_wrap=4)
g.map_dataframe(sns.barplot, x="region", y="profit")

Adjusting histogram in matplotlib [duplicate]

This question already has answers here:
How to create a bar chart/histogram with bar per discrete value?
(1 answer)
Matplotlib xticks not lining up with histogram
(5 answers)
Matplotlib: incorrect histograms
(1 answer)
Python Matplotlib pyplot histogram
(3 answers)
Closed 4 months ago.
I am making a histogram using matplotlib. I am using integer data and I want them to represent 1 bin. The following is the sample code which I made.
import matplotlib.pyplot as plt
a=[1,2,2,3,3,3,4,4,4,4]
plt.figure()
plt.hist(a,bins=4)
plt.show()
The histogram which I got is above. This have left end 1 ad rightend 4. I want the width of the histogram to be 1, however, this will just show 0.75 size. Moreover, I want the x value to locate at the center of the bar of histogram. Is there any way I can adjust?

Legends for hue in seaborn count plot | Change position [duplicate]

This question already has answers here:
Move seaborn plot legend to a different position
(8 answers)
Closed 3 months ago.
In countplot legend for hue are placed at improper positition:
sns.countplot(x='cat114', hue='loss', data=data_tr)
How do I change legend position?
I tried plt.legend(loc='upper right') but it is not helping me.
g=sns.countplot(x=feature, hue='loss', data=data_tr)
g.figure.get_axes()[0].legend(title='loss',loc='upper right')

How to generate color legend for bivariate plots in Seaborn? [duplicate]

This question already has answers here:
Getting legend in seaborn jointplot
(2 answers)
Closed 3 years ago.
When generating bivariate plots like hexbin, pandas generates a legend explaining frequency value for each color shade:
pokemon.plot.hexbin(x='HP', y='Attack', gridsize=30)
I cannot find a similar way to generate such a legend for jointplot and kdeplot in seaborn:
sns.jointplot(data=pokemon, x='HP', y='Attack', kind='hex')
sns.kdeplot(pokemon['HP'], pokemon['Attack'], shade=True)
How can I do it?
for a kdeplot, simply pass cbar=True
cbar : bool, optional
If True and drawing a bivariate KDE plot, add a colorbar.