# Pandas 繪圖

``````import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

x = np.arange(0, 2 * np.pi, np.pi / 180)  # 0 到 2 * PI，步進值 PI / 180
y = np.sin(x)

sin = pd.Series(y, index = x)
sin.plot(title = 'y = sin(x)', xlabel = 'x', ylabel = 'y')

plt.show()
``````

``````import matplotlib.pyplot as plt
import pandas as pd

scores = pd.DataFrame(
[
[90, 99, 100],
[99, 87, 94],
[92, 85, 76],
[87, 67, 72],
[85, 89, 67]
],
columns = ['數學', '英文', '物理']
)

scores.plot(kind = 'scatter', x = '數學', y = '英文')
plt.show()
``````

``````import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

def sierpinski(n):
def quotientAndRemainderZero(elem, n):
quotient = elem // n
remainder = elem % n
return quotient & remainder == 0

quotientAndRemainderZero = np.frompyfunc(quotientAndRemainderZero, 2, 1)

nums = np.arange(n ** 2)
nums = nums[np.where(quotientAndRemainderZero(nums, n))]
return (nums % n, nums // n)

n = 64
x, y = sierpinski(n)

plotwidth = 6
axislim = (-0.5, n - 0.5)
plotsize = (plotwidth, plotwidth)
PTS_PER_INCH = 72
plotwidth_pts = PTS_PER_INCH * plotwidth
markersize = 0.775 * plotwidth_pts / n

tri = pd.DataFrame(np.array([x, y]).T)
tri.plot(
title = 'Sierpinski triangle',
kind = 'scatter',
x = 0,
y = 1,
xlabel = 'x',
ylabel = 'y',
xlim = axislim,
ylim = axislim,
# Matplotlib 的 plot.scatter 方法需要的參數
marker = 's',
s = markersize ** 2
)
plt.show()
``````

``````import matplotlib.pyplot as plt
import pandas as pd

scores = pd.DataFrame(
[
[90, 99, 100],
[99, 87, 94],
[92, 85, 76],
[87, 67, 72],
[85, 89, 67]
],
columns = ['數學', '英文', '物理'],
index = ['No.01', 'No.02', 'No.03', 'No.04', 'No.05']
)

scores.plot()
plt.show()
``````