Numpy histogram no boundaries between bins [duplicate] - python

This question already has answers here:
No outlines on bins of Matplotlib histograms or Seaborn distplots
(3 answers)
Closed 5 years ago.
I wonder why the bins are not showing a boundary between each other. It's confusing to look at it. I attached an example below:
for key,value in dict.items():
plt.figure()
plt.hist( value, bins='auto')
plt.title("Histogram for THR")
plt.show()

That's the new default style for matplotlib 2.0 (for example, see the plots from the documentation for plt.hist in v2.0).
To force the edges of the bins to be displayed you can pass the edgecolor= (or ec=) argument to plt.hist, e.g. plt.hist(values, bins='auto', ec='k') for black bin edges.

Related

Fill a plot with color from a y upwards to infinity [duplicate]

This question already has answers here:
How to use matplotlib fill_between for default ylim
(1 answer)
How to highlight specific x-value ranges
(2 answers)
Closed 2 months ago.
I am trying to indicate a "dangerous" zone in my sns boxplot.
So far this is what i came up with:
plt.fill_between([0, 6], [danger, danger], danger * 1.2, color='salmon', alpha=0.5)
But since I use sns boxplot, the x values are totally messed up and i had to play with it to get the following result:
I cant really increase the polygon size as the plot grows with it (understandingly).
Ideally i would have wanted to simply paint everything above this threshold as red like so:

How can i plot multiple distribution plots with Seaborn? [duplicate]

This question already has answers here:
seaborn distplot / displot with multiple distributions
(6 answers)
Plotting multiple seaborn displot
(1 answer)
seaborn is not plotting within defined subplots
(1 answer)
Closed 9 months ago.
I am not experienced with plotting in Python. But I have managed to plot a signle distribution plot with Seaborn.
example code:
sns.displot(SD_frame_A,kind="kde")
example plot:
So I tryed to plot three of them in one graph:
example code:
sns.displot(SD_frame_A,kind="kde")
sns.displot(SD_frame_S,kind="kde")
sns.displot(SD_frame_D,kind="kde")
plt.show()
But this will only plot the three distribution separately. Does anyone how I can plot both 3 distribution in one plot?
Thanks for reading!
You can't do that with displot because that is a figure-level function. But you can use kdeplot and provide an axes object:
ax = plt.axes()
sns.kdeplot(SD_frame_A, ax=ax)
sns.kdeplot(SD_frame_S, ax=ax)
sns.kdeplot(SD_frame_D, ax=ax)
plt.show()

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.

Scaling and Labelling KDE plots [duplicate]

This question already has answers here:
Matplotlib Legends not working
(4 answers)
How to set the y-axis limit
(8 answers)
Closed 1 year ago.
I plotted PDF using kdeplot. I am having a tough time to scale and label the plots.
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
error = np.array([1,2,2,3,4,4,5])
error2 = np.array([3,3,4,4,4,6])
sns.kdeplot(error, color='blue',label='error')
sns.kdeplot(error2, color='red',label='error2')
plt.show()
I want the blue curve to be labelled as 'error' and red curve to be labelled as 'error2'.
Also, I want to scale the y-axis. It should be in the range of 0 to 1 with 0.1 interval. How can I achieve this?
Thanks in advance
To add a legend, just add
plt.legend()
above plt.show(). To set the limit of the axis, use
ax = plt.gca() # get current axis
ax.set_ylim([0, 1])
To set the ticks accordingly, you can use
ax.set_yticks(np.arange(0, 1.1, 0.1))
(All above plt.show())

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