Matplotlib

Python för R-användare

Daniel Chen

Instructor

Matplotlib-diagram

import matplotlib.pyplot as plt
plt.hist(iris['sepal_length'])
plt.show()

Python för R-användare

Matplotlib spridningsdiagram

plt.scatter(iris['sepal_length'], iris['sepal_width'])
plt.show()

Python för R-användare

Förfina diagrammet

fig, ax = plt.subplots()
ax.scatter(iris['sepal_length'], iris['sepal_width'])
ax.set_title('Sepal Length')
ax.set_xlabel('Sepal Length')
ax.set_ylabel('Sepal Width')
plt.show()

Python för R-användare

Rotera axelmarkeringar

fig, ax = plt.subplots()
ax.scatter(iris['sepal_length'], iris['sepal_width'])
ax.set_title('Sepal Length')
ax.set_xlabel('Sepal Length')
ax.set_ylabel('Sepal Width')
plt.xticks(rotation=45) # rotate the x-axis ticks
plt.show()

Python för R-användare

Delar av en matplotlib-figur

Python för R-användare

Delar av en matplotlib-figur 2

Python för R-användare

Figurer och axlar

fig, ax = plt.subplots()
ax.scatter(iris['sepal_length'], iris['sepal_width'])
plt.show()

Python för R-användare

Flera axlar

fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.scatter(iris['sepal_length'], iris['sepal_width'])
ax2.hist(iris['sepal_length'])
plt.show()

Python för R-användare

Kom ihåg

fig, ax = plt.subplots()
sns.regplot(x='sepal_length', y='sepal_width',
            data=iris, fit_reg=False, ax=ax)
plt.show()

plot

Python för R-användare

Rensa figuren

fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.scatter(iris['sepal_length'], iris['sepal_width'])
ax2.hist(iris['sepal_length'])
plt.show()
plt.clf()

Python för R-användare

Nu kör vi en övning!

Python för R-användare

Preparing Video For Download...