๐จ ๊ทธ๋ํ ์ปค์คํฐ๋ง์ด์ง
1. ๊ทธ๋ํ ํฌ๊ธฐ ์กฐ์ (figsize)

โ
๋ฐฉ๋ฒ 1: pyplot ๋ฐฉ์
plt.figure(figsize=(12, 3))
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
plt.plot(x, y)
plt.title("Plot with Pyplot Interface")
plt.show()
โ
๋ฐฉ๋ฒ 2: subplots ๋ฐฉ์
fig, ax = plt.subplots(figsize=(12, 3))
x = [1, 2, 3, 4, 5]
y = [1, 9, 16, 25, 32]
ax.plot(x, y)
ax.set_title('PLo')
plt.show()
๐ ๋ฉ์๋ ์ค๋ช
plt.figure(figsize=(w,h)) : pyplot ๋ฐฉ์์ผ๋ก ๊ทธ๋ํ ํฌ๊ธฐ ์ง์ (์ธ์น ๋จ์)
plt.subplots(figsize=(w,h)) : ๊ฐ์ฒด์งํฅ ๋ฐฉ์์์๋ ํฌ๊ธฐ ์ง์
2. ์ถ ๋ฒ์ ์ง์ (set_xlim, set_ylim)

x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.figure(figsize=(8, 4.5))
plt.plot(x, y)
plt.xlim(0, 5)
plt.ylim(10, 30)
plt.show()
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.plot(x, y)
ax.set_xlim(0, 5)
ax.set_ylim(10, 30)
plt.show()
๐ ๋ฉ์๋ ์ค๋ช
plt.xlim() / plt.ylim() : pyplot ๋ฐฉ์ ์ถ ๋ฒ์ ์กฐ์
ax.set_xlim() / ax.set_ylim() : ๊ฐ์ฒด์งํฅ ๋ฐฉ์ ์ถ ๋ฒ์ ์ค์
3. ์ถ ๋ค์ง๊ธฐ (invert_yaxis)

plt.figure(figsize=(8, 4.5))
plt.plot(x, y)
plt.gca().invert_yaxis()
plt.show()
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.plot(x, y)
ax.invert_yaxis()
plt.show()
๐ ๋ฉ์๋ ์ค๋ช
gca() : ํ์ฌ ํ์ฑํ๋ ์ถ์ ๋ฐํ
invert_yaxis() : y์ถ ๋ฐฉํฅ์ ์์๋ ๋ฐ์
4. ๋๊ธ์/๋ณด์กฐ ๋๊ธ (minorticks_on, grid)

x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
fig, ax = plt.subplots(figsize=(8, 3))
ax.plot(x, y)
ax.minorticks_on()
ax.grid(which='major', axis='both', color='red', linestyle='-.', linewidth=2)
ax.grid(which='minor', axis='both', color='red', linestyle=':', linewidth=0.5)
plt.show()
๐ ๋ฉ์๋ ์ค๋ช
minorticks_on() : ๋ณด์กฐ ๋๊ธ ํ์
grid() : ๋๊ธ์ ์ค์ (which=major/minor, axis=x/y/both ๋ฑ ์กฐ์ ๊ฐ๋ฅ)
5. ๋๊ธ ๋ผ๋ฒจ ์ง์ (xticks, yticks, set_xticks, set_xticklabels)

โ
pyplot ๋ฐฉ์
x = [1, 2, 3, 4]
y = [2, 4, 8, 16]
plt.figure(figsize=(8, 3))
plt.plot(x, y)
plt.xticks([1, 2, 3, 4], ['ํ๋', '๋์๊ธฐ', '์์ผ', '๋๊ตฌ๋ฆฌ'])
plt.yticks([3, 5, 9, 17], ['1', '2', '3', '4'])
plt.show()
โ
subplots ๋ฐฉ์
fig, ax = plt.subplots(figsize=(8, 3))
ax.plot(x, y)
ax.set_xticks([1, 2, 3, 4])
ax.set_xticklabels(['ํ๋', '๋์๊ธฐ', '์์ผ', '๋๊ตฌ๋ฆฌ'])
ax.set_yticks([2, 4, 8, 16])
plt.show()
๐ ๋ฉ์๋ ์ค๋ช
xticks() / yticks() : ๋๊ธ ๊ฐ ๋ฐ ๋ผ๋ฒจ ์ง์ (pyplot ๋ฐฉ์)
set_xticks() / set_xticklabels() : axes ๊ฐ์ฒด ๊ธฐ์ค์ผ๋ก ๋๊ธ ๋ผ๋ฒจ ์ง์
6. ์ ๋ชฉ, ์ถ ๋ผ๋ฒจ, ๋ฒ๋ก ์ค์

โ
pyplot ๋ฐฉ์
x = [1, 3, 5, 7, 9, 11, 13]
y = [10, 20, 30, 45, 80, 95, 100]
plt.plot(x, y, label='์ฌ์ฝ์ ์๋ธํ๋กฏ์ด๋ค', color='#1B1B1B', linestyle='--', marker='o')
plt.xlabel('xname')
plt.ylabel('yname')
plt.title('์์ฌ๋ค ํ์
จ์ด์?')
plt.legend()
plt.show()
โ
subplots ๋ฐฉ์
x = [1, 2, 3, 4, 5]
y = [10, 18, 15, 48, 96]
fig, ax = plt.subplots()
ax.plot(x, y, label='์ฌ์ฝ์ ์๋ธํ๋กฏ์ด๋ค', color='#1B1B1B', linestyle='--', marker='o')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_title('๊ฐ์ฒด ์งํฅ ์ธํฐํ์ด์ค')
ax.legend()
plt.show()
๐ ๋ฉ์๋ ์ค๋ช
title() / set_title() : ๊ทธ๋ํ ์ ๋ชฉ ์ค์
xlabel() / set_xlabel() : x์ถ ์ด๋ฆ ์ค์
ylabel() / set_ylabel() : y์ถ ์ด๋ฆ ์ค์
legend() / ax.legend() : ๋ฒ๋ก ํ์ (label ์ง์ ํ์)
7. ๋ฒ๋ก ์ปค์คํฐ๋ง์ด์ง (legend() ์ธ์ ํ์ฉ)

x = [1, 2, 3, 4, 5]
y1 = [1, 4, 2, 3, 7]
y2 = [2, 2, 3, 1, 6]
plt.figure(figsize=(9, 6), facecolor='Cyan')
plt.plot(x, y1, label='Data set1')
plt.plot(x, y2, label='Data set2')
plt.legend(loc='best', fontsize=16, shadow=True, title='Legend')
plt.show()
fig, ax = plt.subplots(figsize=(16, 9), facecolor='black')
x = [1, 2, 3, 4, 5]
y1 = [1, 4, 2, 3, 7]
y2 = [6, 5, 1, 7, 3]
ax.plot(x, y1, label='y1')
ax.plot(x, y2, label='y2')
ax.legend(loc='upper right', fontsize=16, shadow=True, title='THAD')
plt.show()
๐ ์ฃผ์ ์ธ์ ์ค๋ช
loc : ๋ฒ๋ก ์์น ์ง์ ('best', 'upper right', 'lower left' ๋ฑ)
fontsize : ๊ธ์ ํฌ๊ธฐ
shadow : ๊ทธ๋ฆผ์ ํจ๊ณผ
title : ๋ฒ๋ก ์๋จ ์ ๋ชฉ ์ถ๊ฐ