๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐Ÿฆ• ๊ณต๋ฃก์ด ๋˜์ž!

Matplotlib...2(๊ทธ๋ž˜ํ”„ ์˜ต์…˜ 1) ๋ณธ๋ฌธ

Development/Python

Matplotlib...2(๊ทธ๋ž˜ํ”„ ์˜ต์…˜ 1)

Kirok Kim 2022. 2. 5. 23:13
  • %matplotlib qt: ํŒ์—…์ฐฝ์—์„œ ๊ทธ๋ž˜ํ”„๋ฅผ ์ถœ๋ ฅํ• ๋•Œ %matplotlib inline : ๊ฒฐ๊ณผ๋ถ€๋ถ„ ์ถœ๋ ฅ
  • plt.figure(1~) : 1~๋ฒˆ ๊ทธ๋ž˜ํ”„(๋ฐฑ์ง€) ์ƒ์„ฑ
  • plt.show() : ์ด๋•Œ๊นŒ์ง€ ๊ทธ๋ฆฐ ๊ฒƒ ๋ณด์—ฌ์ฃผ๊ธฐ
  • plt.clf() : ๊ทธ๋ž˜ํ”„๋ฅผ ๋ชจ๋‘ ์ง€์šฐ๊ธฐ
  • plt.subplot(m,n,p) : m*nํ–‰๋ ฌ๋กœ ์ด๋ค„์ง„ ํ•˜์œ„ ๊ทธ๋ž˜ํ”„ ์ค‘์—์„œ p๋ฒˆ ์œ„์น˜์— ๊ทธ๋ž˜ํ”„๊ฐ€ ๊ทธ๋ ค์ง€๋„๋ก ์ง€์ • p๋Š” ์™ผ์ชฝ์—์„œ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊ทธ๋ฆฌ๊ณ  ์œ„์—์„œ ์•„๋ž˜๋กœ ํ–‰๋ ฌ์˜ ์œ„์น˜๋ฅผ ์ง€์ •
  • 211    221 222    321 322
    212    223 224    323 324
                      325 326โ€‹
    • ์ฐธ๊ณ  ์˜ˆ์ œ
    • plt.subplot(2,2,1)
      plt.plot(x,y1)
      
      plt.subplot(2,2,2)
      plt.plot(x,y2)
      
      plt.subplot(2,2,3)
      plt.plot(x,y3)
      
      plt.show()
      
  • ๊ทธ๋ž˜ํ”„
    • ์ถœ๋ ฅ๋ฒ”์œ„ ์ง€์ •ํ•˜๊ธฐ
      • xlimit
        • plt.xlim(min. max)
      • ylim
        • plt.ylim(min, max)
    • ์„ค์ •
      • ์ถ• ์ œ๋ชฉ
        • plt.xlabel('X-axis')
        • plt.ylabel('Y-axis')
      • ๊ทธ๋ž˜ํ”„ ์ œ๋ชฉ
        • plt.title('Graph title')
      • ๊ฒฉ์ž ์ œ๋ชฉ
        • plt.grid(True)
      • ๋ฒ”๋ก€ ์ œ๋ชฉ
        • ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ ์˜ต์…˜์„ค์ •๋•Œ label=’’ ๋กœ ๋ฏธ๋ฆฌ ์„ค์ • ๊ฐ€๋Šฅ
          • ์˜ˆ์ œ
          • plt.plot(์„ฑ๋ณ„์„ ์‹ค๋“ฑ๊ธ‰๋ณ„์ƒ์กด์œจ.loc['female'], label='female')
            plt.plot(์„ฑ๋ณ„์„ ์‹ค๋“ฑ๊ธ‰๋ณ„์ƒ์กด์œจ.loc['male'], label='male')
            
        • plt.legend(['data1',~~],loc='์œ„์น˜')
          • legend() ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋ฒ”๋ก€๊ฐ€ ์ƒ์„ฑ๋จ
          • best 0
            upper right 1
            upper left 2
            lower left 3
            lower right 4
            right 5
            center left 6
            center right 7
            lower center 8
            upper center 9
            center 10
        • ๊ฐ’ ํ‘œ์‹œ
          • plt.text(x,y,name)

๋ฐ˜์‘ํ˜•

'Development > Python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

ex(์ฒจ๋„, ๋ถ„์‚ฐ,๋ฐ•์Šค)  (0) 2022.02.07
Matplotlib...3(๊ทธ๋ž˜ํ”„ ์˜ต์…˜ 2)  (0) 2022.02.06
Matplotlib...1(๊ทธ๋ž˜ํ”„ ํ˜•์‹)  (0) 2022.02.04
2BPerfect...18  (0) 2022.02.03
2BPerfect...17  (0) 2022.02.02
Comments