0% found this document useful (0 votes)
29 views31 pages

Lab 2

Uploaded by

ngocthanh2821
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views31 pages

Lab 2

Uploaded by

ngocthanh2821
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

APPLIED STATISTICS

IN ENVIRONMENT
COURSE CODE: ENEE1006IU

Lab-works
Applications of Python
Part 2 – Graphics
(3 credits: 2 is for lecture, 1 is for lab-work)
Instructor: TRAN THANH TU
Email: [email protected]

[email protected] 47
Graphics with Python
Description
distplot histogram
barplot estimate of central tendency for a numeric variable
violinplot similar to boxplot, also shows the probability
density of the data
Numpy
jointplot Scatterplot
Pandas
regplot Regression plot Matplotlib
pairplot Pairplot Seaborn
boxplot boxplot Plotly
Ggplot
swarmplot categorical scatterplot
factorplot General categorical plot
[email protected] 48
Graphics with Python
Numpy

[email protected] 49
Graphics with Python
Scatter plot
Pandas

Matplotlib

Seaborn

[email protected] 50
Graphics with Python
Scatter plot
Matplotlib

Seaborn

[email protected] 51
Graphics with Python
Line chart
Pandas

Matplotlib

Seaborn
[email protected] 52
Graphics with Python
Bar chart
Pandas

[email protected] 53
Graphics with Python
Bar chart
Matplotlib

Seaborn

[email protected] 54
Graphics with Python
Histogram
Pandas

Matplotlib

Seaborn

[email protected] 55
Graphics with Python
Heatmap
Matplotlib

Seaborn

[email protected] 56
Graphics with Python
Pandas – Multiple Histogram

[email protected] 57
Graphics with Python
Pandas – Boxplot

[email protected] 58
Graphics with Python
Matplotlib - Pie

[email protected] 60
Graphics with Python
Matplotlib – 3D
particle configuration: “pos”

[email protected] 61
Graphics with Python
Matplotlib – 3D
particle configuration: “pos”
velocity configuration: “vel”
velocity squared: “v2”
“v2” on “pos” is like a scalar field.

[email protected] 62
Graphics with Python
Seaborn - Faceting

[email protected] 63
Graphics with Python
Seaborn – Pairplot

[email protected] 64
Graphics with Python
Seaborn – Pairplot

[email protected] 65
Graphics with Python
Seaborn

[email protected] 66
Graphics with Python
Plotly

[email protected] 67
Graphics with Python
Plotly

[email protected] 68
Graphics with Python
ggplot - geom_point
ggplot(mpg, aes(x='carat', y='price',
color='clarity'), diamonds) + geom_point()

ggplot(aes(x='carat', y='price',
shape="cut"), diamonds) + geom_point()

[email protected] 69
Graphics with Python
ggplot - geom_line

ggplot(mpg, aes(x = displ, y = cty)) +


geom_point() + geom_line()

[email protected] 70
Graphics with Python
ggplot - stat_smooth
ggplot(aes(x='date', y='beef'), data=meat) +
geom_point() + \
stat_smooth(method='loess')

[email protected] 71
Graphics with Python
ggplot - stat_density
ggplot(aes(x='price', color='clarity'),
data=diamonds) + stat_density()

[email protected] 72
Graphics with Python
ggplot - scale_x_log

ggplot(diamonds, aes(x='price')) +
geom_histogram() + scale_x_log(base=100)

[email protected] 73
Graphics with Python
ggplot - coord

df = pd.DataFrame({"x": np.arange(100)})
df['y'] = df.x * 10 # polar coords
p = ggplot(df, aes(x='x', y='y')) +
geom_point() + coord_polar() print(p)

[email protected] 74
Graphics with Python
ggplot - facets

ggplot(diamonds, aes(x='price')) + \
geom_histogram() + \
facet_grid("cut")

[email protected] 75
Graphics with Python
ggplot - facets

ggplot(chopsticks,
aes(x='chopstick_length',
y='food_pinching_effeciency')) + \
geom_point() + \
geom_line() + \
scale_x_continuous(breaks=[150, 250, 350])
+ \ facet_wrap("individual")
[email protected] 76
Graphics with Python
ggplot - facets
ggplot(diamonds, aes(x="carat", y="price",
color="color", shape="cut")) + geom_point()
+ facet_wrap("clarity")

[email protected] 77
Graphics with Python
ggplot - tips
n You can annotate plots
ggplot(mtcars, aes(x='mpg')) + geom_histogram()
+ \
xlab("Miles per Gallon") + ylab("# of
Cars")
n Assign a plot to a variable, for instance g:
g = ggplot(mpg, aes(x = displ,
y = cty)) + geom_point()

n The function save saves the plot to the desired


format: g.save(“myimage.png”)
[email protected] 78

You might also like