
plt.show()를 해야 차트가 시각화되어 보이게 됨plt.show() 없이도 차트가 줄력됨| State-based | Object-oriented |
|---|---|
| >> plt.figure() | >> fig, ax = plt.subplots() |
| >> plt.plot(x,y) | >> ax.plot(x,y) |
plt.{method} 형식의 문법으로 그래프를 그림ax.{메서드}의 형식으로 그래프를 그림import numpy as np
import matplotlib.pyplot as plt
# data
data1, data2, data3 = np.random.randn(3, 20)
fig = plt.figure(figsize=(14,12))
<Figure size 1400x1200 with 0 Axes>
fig = plt.figure(figsize=(14,12))
plt.subplot(1,2,1) # plt.subplot(121)
plt.scatter(data1,data2)
<matplotlib.collections.PathCollection at 0x7fe8bcf3d110>

fig = plt.figure(figsize=(14,12))
plt.subplot(1,2,1) # plt.subplot(121)
plt.scatter(data1,data2)
plt.subplot(1,2,2) # plt.subplot(122)
plt.plot(data3,'r')
[<matplotlib.lines.Line2D at 0x7fe8bc148890>]

fig = plt.figure(figsize=(14,12))
plt.subplot(1,2,1) # plt.subplot(121)
plt.scatter(data1,data2)
plt.subplot(1,2,2) # plt.subplot(122)
plt.plot(data3,'r')
plt.xlabel("X_axis")
plt.ylabel("Y_axis")
plt.show()

fig, (ax1, ax2) = plt.subplots(1,2,figsize=(14,12))

fig, (ax1, ax2) = plt.subplots(1,2,figsize=(14,12))
ax1.scatter(data1, data2)
<matplotlib.collections.PathCollection at 0x7fe8bc1f5110>

fig, (ax1, ax2) = plt.subplots(1,2,figsize=(14,12))
ax1.scatter(data1, data2)
ax2.plot(data3,'r')
[<matplotlib.lines.Line2D at 0x7fe8a86d7bd0>]

fig, (ax1, ax2) = plt.subplots(1,2,figsize=(14,12))
ax1.scatter(data1, data2)
ax2.plot(data3,'r')
ax1.set_xlabel("Axes 1-X_axis")
ax1.set_ylabel("Axes 1-Y_axis")
ax2.set_xlabel("Axes 2-X_axis")
ax2.set_ylabel("Axes 2-Y_axis")
plt.show()

fig = plt.figure(figsize=(14,12))
ax1 = plt.subplot(1,2,1) # plt.subplot(121)
ax1.scatter(data1,data2)
ax2 = plt.subplot(1,2,2) # plt.subplot(122)
ax2.plot(data3,'r')
ax1.set_xlabel("Axes 1-X_axis")
ax1.set_ylabel("Axes 1-Y_axis")
ax2.set_xlabel("Axes 2-X_axis")
ax2.set_ylabel("Axes 2-Y_axis")
plt.show()

Matplotlib Quick start guide
Matplotlib's documentation and examples use both the OO and the pyplot styles. In general, we suggest using the OO style, particularly for complicated plots, and functions and scripts that are intended to be reused as part of a larger project. However, the pyplot style can be very convenient for quick interactive work.
