1. iplot

๐Ÿ“Š ์ฒซ ์‹œ๊ฐํ™” ํฌ์ŠคํŒ…์ด๋‹ค!! ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ / ์‹œ๊ฐํ™” ์‹ค์Šตํ•  ๋•Œ ์‚ฌ์šฉํ•œ ํˆด์ด iplot๊ณผ plotly์ธ๋ฐ, ์ด๋ฒˆ์—๋Š” ๋” ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์‹œ๊ฐํ™”๋ฅผ ํ•  ์ˆ˜ ์žˆ๋Š” iplot์„ ๋จผ์ € ์•Œ์•„๋ณด์ž.


1.1. iplot ์‚ฌ์šฉํ•˜๊ธฐ


๐Ÿ“Š ์ผ๋‹จ์€ iplot์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ chart_studio ์™€ cufflinks๋ฅผ ์„ค์น˜ํ•ด์ฃผ์ž.

!pip install plotly chart_studio --upgrade
!pip install cufflinks --upgrade

๐Ÿ“Š ์ด์ œ๋Š” ๋‘ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ž„ํฌํŠธํ•˜์ž.

import chart_studio.plotly as py
import cufflinks as cf
cf.go_offline(connected = True)

iplot์„ ์‚ฌ์šฉํ•  ์ค€๋น„๊ฐ€ ๋๋‚ฌ๋‹ค๐Ÿ™ƒ.

1.2. iplot ๊ธฐ๋ณธํ˜•ํƒœ


๐Ÿ“Š dataframe.iplot(kind = โ€˜๊ทธ๋ž˜ํ”„ ์ข…๋ฅ˜โ€™)

  • df.iplot(kind = โ€˜barโ€™) - bar ๊ทธ๋ž˜ํ”„ ์ž‘์„ฑ
  • df.iplot(kind = โ€˜barโ€™, barmode = โ€˜stackโ€™) - ๋ˆ„์ ๊ทธ๋ž˜ํ”„ ์ž‘์„ฑ
  • df.iplot(kind = โ€˜barโ€™, barmode = โ€˜stackโ€™, orientation = โ€˜hโ€™) - ๊ฐ€๋กœ๋กœ ๊ทธ๋ž˜ํ”„ ์ž‘์„ฑ

  • df.iplot(kind = โ€˜scatterโ€™) - line ๊ทธ๋ž˜ํ”„ ์ž‘์„ฑ
  • df.iplot(kind = โ€˜scatterโ€™, mode = โ€˜lines + markersโ€™) - ์„ /์  ๋ชจ๋‘ ๋‚˜ํƒ€๋ƒ„
  • df.iplot(kind = โ€˜scatterโ€™, fill = True) - line ์•„๋žซ๋ถ€๋ถ„์„ ์ฑ„์›Œ์คŒ
  • df.iplot(kind = โ€˜scatterโ€™, xTitle = โ€˜ x title โ€™, yTitle = โ€˜ y title โ€™, title = โ€˜ title โ€˜) - ํƒ€์ดํ‹€ ์„ค์ •

๐Ÿ“Š iplot ์˜ x์ถ• ๊ธฐ์ค€์€ ์ธ๋ฑ์Šค์ด๋‹ค. ์›ํ•˜๋Š” x์ถ•์ด ์žˆ๋Š” ๊ฒฝ์šฐ์—๋Š” ๋ฏธ๋ฆฌ ๊ทธ ๊ฐ’์„ ์ธ๋ฑ์Šค๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ํŽธํ• ๋“ฏ!!

1.3. ์‹œ๋ฆฌ์ฆˆ๋กœ ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ


๐Ÿ“Š df[โ€˜columnโ€™].iplot(kind = โ€˜๊ทธ๋ž˜ํ”„ ์ข…๋ฅ˜โ€™)

1.4. ๊ทธ๋ž˜ํ”„ ํ…Œ๋งˆ ๊ฐ€์ ธ์˜ค๊ธฐ


๐Ÿ“Š ๊ทธ๋ž˜ํ”„์— ์—ฌ๋Ÿฌ ํ…Œ๋งˆ๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

cf.getThemes( )
>> ['ggplot', 'pearl', 'solar', 'space', 'white', 'polar', 'henanigans']
for themes in cf.getThemes:
    df.iplot(kind = 'bar', theme = themes, title = themes)

1.5. ๋ ˆ์ด์•„์›ƒ ๋งŒ๋“ค๊ธฐ - ๋”•์…”๋„ˆ๋ฆฌ


  • title : ๊ทธ๋ž˜ํ”„์˜ ์ œ๋ชฉ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋”•์…”๋„ˆ๋ฆฌ - ์ œ๋ชฉ์˜ ๋‚ด์šฉ๊ณผ ํฐํŠธ(์‚ฌ์ด์ฆˆ / ๊ธ€์ž์ƒ‰), x์ถ• / y์ถ• ๊ธฐ์ค€ ์ œ๋ชฉ์˜ ์œ„์น˜๋ฅผ ์ง€์ •ํ•จ
  • plot_bgcolor : ๊ทธ๋ž˜ํ”„์˜ ๋’ท๋ฐฐ๊ฒฝ ์ƒ‰๊น” ์ง€์ •
  • xaxis / yaxis : x์ถ•,y์ถ•์„ ์ƒ์„ธ์กฐ์ •ํ•จ
    • showticklabels : tick์„ ๋ณด์—ฌ์ค„๊ฒƒ์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •
    • dtick : tick์˜ ๊ฐ„๊ฒฉ์„ ์ง€์ •
    • title : ๊ฐ ์ถ•์˜ ์ œ๋ชฉ, ์‚ฌ์ด์ฆˆ, ๊ธ€์ž์ƒ‰ ์ง€์ •
layout = {
    'title' : {'text' : , 'font' : {'size' : , 'color' : }, 'x' : 0.5, 'y' : 0.9 },
    
    'plot_bgcolor' : #์ƒ‰์ƒ์ฝ”๋“œ,
    
    'xaxis' : {'showticklabels' : True / False, 'dtick' : 2,
               'title' : {'text' : , 'font' : {'size' : , 'color' : }}}
    
    'yaxis' : {'showticklabels' : True / False, 'dtick' : 5,
               'title' : {'text' : , 'font' : {'size' : , 'color' : }}}
}
    
df.iplot(kind = 'scatter', mode = 'lines+markers', layout = layout)

๐Ÿ“Š ํ•˜์ง€๋งŒ layout์„ ์„ ์–ธํ•˜๊ณ  ํ…Œ๋งˆ ์ ์šฉ์€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ˆ ์ด ์ ์— ์œ ์˜ํ•˜๋„๋ก ํ•˜์ž.

๐Ÿ“Š iplot์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ธฐ๋Šฅ๋„ ์ง€์›ํ•œ๋‹ค.

 df.iplot(kind = 'scatter', theme = 'ggplot', title = 'Iplot layout', xTitle = 'x title', yTitle = 'ytitle')
  • ์ด๋Ÿฐ ๋ฐฉ๋ฒ•๋„ ์žˆ์ง€๋งŒ ์ข€ ๋” ์„ธ๋ฐ€ํ•˜๊ฒŒ ์‹œ๊ฐํ™”ํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋ ˆ์ด์•„์›ƒ์„ ๋งŒ๋“ค์–ด์ค€๋‹ค.
  • ๋น ๋ฅด๊ฒŒ ๊ฐœํ˜• ์ •๋„๋งŒ ํ™•์ธํ•  ๋•Œ๋Š” ์œ„์˜ ๋ฐฉ๋ฒ•์ฒ˜๋Ÿผ ๊ฐ„๊ฒฐํžˆ ์‹œ๊ฐํ™”ํ•˜๋Š” ๊ฒƒ๋„ ๊ดœ์ฐฎ์„ ๋“ฏํ•˜๋‹ค๐Ÿ™ƒ.
  • ๋˜ํ•œ ์œ„์˜ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ„๊ฒฐํ•œ layout์— theme๋„ ์ ์šฉ์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ฐธ๊ณ ํ•˜์ž!!

๐Ÿ“Š ๊ฐœ์ธ์ ์œผ๋กœ๋Š” ์‹œ๊ฐํ™”๋ฅผ ํ• ๋–„ matplotlib ๋ณด๋‹ค iplot์ด๋‚˜ plotly๋ฅผ ์„ ํ˜ธํ•˜๋Š” ํŽธ์ด๋‹ค. ๋น„๊ต์  ์ตœ๊ทผ์— ๋‚˜์˜จ ์‹œ๊ฐํ™” ํˆด์ด๊ธฐ ๋–„๋ฌธ์— ์ข€ ๋” ์ง๊ด€์ ์ด๊ณ  ๊ฐ„๊ฒฐํ•œ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๊ธฐ ๋–„๋ฌธ์ด๋‹ค. ๋ฌผ๋ก  ๊ทธ๋ ‡๋‹ค๊ณ  matplolib ์„ ์•„์˜ˆ ๋ชจ๋ฅด๋ฉด ์•ˆ๋˜๊ฒ ์ง€๋งŒ ํŽธํ•œ ๊ฒƒ์— ์†์ด ๊ฐ€๋Š” ๊ฑด ์–ด์ฉ” ์ˆ˜ ์—†๋‚˜๋ณด๋‹คใ…Ž

๐Ÿ“Š ๋‹ค์Œ ํฌ์ŠคํŒ…์—์„œ๋Š” plotly ์‚ฌ์šฉ๋ฒ•์„ ๋ฐฐ์›Œ๋ณด์ž!!

Leave a comment