Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
SciPy Recipes

You're reading from   SciPy Recipes A cookbook with over 110 proven recipes for performing mathematical and scientific computations

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788291460
Length 386 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
 Martins Martins
Author Profile Icon Martins
Martins
Ruben Oliva Ramos Ruben Oliva Ramos
Author Profile Icon Ruben Oliva Ramos
Ruben Oliva Ramos
V Kishore Ayyadevara V Kishore Ayyadevara
Author Profile Icon V Kishore Ayyadevara
V Kishore Ayyadevara
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Getting to Know the Tools FREE CHAPTER 2. Getting Started with NumPy 3. Using Matplotlib to Create Graphs 4. Data Wrangling with pandas 5. Matrices and Linear Algebra 6. Solving Equations and Optimization 7. Constants and Special Functions 8. Calculus, Interpolation, and Differential Equations 9. Statistics and Probability 10. Advanced Computations with SciPy

Generating histograms and box plots


Matplotlib supports the creation of a variety of displays of data. In this recipe, we will demonstrate how to use two popular graphs representing data variability: histograms and box plots (also known as box-and-whisker plots). We will present a comparison between the distribution of heights in the male and female populations. To make the example self-contained, instead of using real data, we will simulate a population with the known distribution of heights for males and females.

Getting ready

Start Jupyter and run the following three commands in an execution cell:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

How to do it…

Run the following code in a Jupyter code cell:

from scipy.stats import norm
mmean, msdev = 70, 4.0
fmean, fsdev = 65, 3.5
mdist = norm(mmean, scale=msdev)
fdist = norm(fmean, scale=fsdev)
nm, nf = 2000, 1500
mdata = mdist.rvs(size=nm)
fdata = fdist.rvs(size=nf)
plt.figure(figsize=(12, 4))
plt.subplot(1,2,1)
plt.hist...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images