Logo Passei Direto
Buscar
Material
páginas com resultados encontrados.
páginas com resultados encontrados.
left-side-bubbles-backgroundright-side-bubbles-background

Crie sua conta grátis para liberar esse material. 🤩

Já tem uma conta?

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

left-side-bubbles-backgroundright-side-bubbles-background

Crie sua conta grátis para liberar esse material. 🤩

Já tem uma conta?

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

left-side-bubbles-backgroundright-side-bubbles-background

Crie sua conta grátis para liberar esse material. 🤩

Já tem uma conta?

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

left-side-bubbles-backgroundright-side-bubbles-background

Crie sua conta grátis para liberar esse material. 🤩

Já tem uma conta?

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Prévia do material em texto

Arseny Turin
Follow 254 Followers About
How To Make Your Histogram Shine
Arseny Turin Dec 28, 2018 · 2 min read
This is a quick tutorial on how to make awesome histograms using matplotlib patches
Why Histogram?
A histogram is a plot that lets you discover, and show, the underlying frequency
distribution (shape) of a set of continuous data. This allows the inspection of the data for
its underlying distribution (e.g., normal distribution), outliers, skewness, etc. —
(statistics.laerd.com)
For this particular tutorial we are going to use Matplotlib. It is the most widely used
open-source plotting library for the Python created in 2003 by John D. Hunter,
American neurobiologist. It is fairly easy to use, highly customizable and is go to tool
for data analysis.
Basic Histogram
Lets take a look at the “regular” histogram. It has style and custom colors and looks
nice.
import matplotlib.pyplot as plt # importing matplotlib 
import numpy as np # importing numpy
x = np.random.normal(0, 1, 6000) # normal distribution
plt.figure(figsize=(14,7)) # Make it 14x7 inch 
plt.style.use('seaborn-whitegrid') # nice and clean grid
Open in app
https://medium.com/@arseniytyurin?source=post_page-----69e432be39ca--------------------------------
https://medium.com/@arseniytyurin/followers?source=post_page-----69e432be39ca--------------------------------
https://medium.com/@arseniytyurin/about?source=post_page-----69e432be39ca--------------------------------
https://medium.com/@arseniytyurin?source=post_page-----69e432be39ca--------------------------------
https://medium.com/@arseniytyurin?source=post_page-----69e432be39ca--------------------------------
https://medium.com/@arseniytyurin/how-to-make-your-histogram-shine-69e432be39ca?source=post_page-----69e432be39ca--------------------------------
https://statistics.laerd.com/statistical-guides/understanding-histograms.php
https://rsci.app.link/?%24canonical_url=https%3A%2F%2Fmedium.com%2Fp%2F69e432be39ca&~feature=LiOpenInAppButton&~channel=ShowPostUnderUser&~stage=mobileNavBar&source=post_page-----69e432be39ca--------------------------------
https://medium.com/?source=post_page-----69e432be39ca--------------------------------
plt.hist(x, bins=90, facecolor = '#2ab0ff', edgecolor='#169acf', 
linewidth=0.5)
plt.title('Normal Distribution') 
plt.xlabel('Bins') 
plt.ylabel('Values') 
plt.show()
Basic Histogram
We get the job done, but there is nothing exciting about it. Same old histogram we’ve
seen a million times.
Make It Shine!
To really impress your boss during the presentation you may want to go an extra mile
and ask yourself: but how can I make cool gradient where each bin has its own color?
The answer is patches. Each patch represents a single bin and we can apply same
options to it as we do to the whole histogram, such as color, opacity, width and so on.
To see all the methods you can apply to each patch use help(patches[0]). The code is
pretty straightforward, lets dive right into it:
... 
n, bins, patches = plt.hist(x, bins=90, facecolor='#2ab0ff', 
edgecolor='#e0e0e0', linewidth=0.5, alpha=0.7) 
n = n.astype('int') # it MUST be integer
# Good old loop. Choose colormap of your taste 
for i in range(len(patches)): 
 patches[i].set_facecolor(plt.cm.viridis(n[i]/max(n)))
# Make one bin stand out 
patches[47].set_fc('red') # Set color 
patches[47].set_alpha(1) # Set opacity
# Add annotation 
plt.annotate('Important Bar!', xy=(0.57, 175), xytext=(2, 130), 
fontsize=15, arrowprops=
{'width':0.4,'headwidth':7,'color':'#333333'})
# Add title and labels with custom font sizes 
plt.title('Normal Distribution', fontsize=12) 
plt.xlabel('Bins', fontsize=10) 
plt.ylabel('Values', fontsize=10) 
plt.show()
Now this looks fancy and functional! Please see full code here
Data Science Histogram Matplotlib
https://github.com/arseniyturin/matplotlib_histogram
https://medium.com/tag/data-science
https://medium.com/tag/histograms
https://medium.com/tag/matplotlib
About Help Legal
Get the Medium app
https://medium.com/?source=post_page-----69e432be39ca--------------------------------
https://medium.com/about?autoplay=1&source=post_page-----69e432be39ca--------------------------------
https://help.medium.com/hc/en-us?source=post_page-----69e432be39ca--------------------------------
https://policy.medium.com/medium-terms-of-service-9db0094a1e0f?source=post_page-----69e432be39ca--------------------------------
https://itunes.apple.com/app/medium-everyones-stories/id828256236?pt=698524&mt=8&ct=post_page&source=post_page-----69e432be39ca--------------------------------
https://play.google.com/store/apps/details?id=com.medium.reader&source=post_page-----69e432be39ca--------------------------------

Mais conteúdos dessa disciplina