๐ŸŽจ ๊ทธ๋ž˜ํ”„ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•|๋„ˆ๋ฌด ์žฌ๋ฐŒ๋•…;;;

์•„๋‡จ ๋ฏผ๊ท ๋ฐ์š”ยท2025๋…„ 6์›” 14์ผ
0

๋ฐ์ดํ„ฐ๋ถ„์„!

๋ชฉ๋ก ๋ณด๊ธฐ
12/12
post-thumbnail

๐ŸŽจ ๊ทธ๋ž˜ํ”„ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•

1. ๊ทธ๋ž˜ํ”„ ํฌ๊ธฐ ์กฐ์ ˆ (figsize)

โœ… ๋ฐฉ๋ฒ• 1: pyplot ๋ฐฉ์‹

plt.figure(figsize=(12, 3))  # ๊ฐ€๋กœ 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))  # fig์™€ ax ๊ฐ์ฒด์— ํฌ๊ธฐ ์„ค์ •
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)  # x์ถ• ๋ฒ”์œ„ ์ง€์ •
plt.ylim(10, 30)  # y์ถ• ๋ฒ”์œ„ ์ง€์ •
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()  # ํ˜„์žฌ ์ถ•(gca)์„ ๊ฐ€์ ธ์™€ y์ถ• ๋’ค์ง‘๊ธฐ
plt.show()
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.plot(x, y)
ax.invert_yaxis()  # y์ถ• ๋ฐ˜์ „
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')  # x์ถ• ๋ผ๋ฒจ ์„ค์ •
plt.ylabel('yname')  # y์ถ• ๋ผ๋ฒจ ์„ค์ •
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')  # x์ถ• ๋ผ๋ฒจ
ax.set_ylabel('Y')  # 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 : ๋ฒ”๋ก€ ์ƒ๋‹จ ์ œ๋ชฉ ์ถ”๊ฐ€

profile
this man์„ ๊ฟˆ ์†์—์„œ ๋ณด์‹  ์ ์ด ์žˆ์œผ์‹ ๊ฐ€์š”?

0๊ฐœ์˜ ๋Œ“๊ธ€