æ°ããRubyåãããããã©ã¤ãã©ãªNyaplot
ã¯ããã«
Google Summer of Code 2014ã«SciRubyã®å¦çã¨ãã¦åå ãã¦ãã¾ããã 3ãæã®æéãç¡äºçµäºããã¡ããã¨ããææç©ãã§ããã®ã§è¨äºã«ãã¾ãã Nyaplotã«ã¤ãã¦ãã³ã¼ãã詳ãã使ãæ¹ã¯ãã¡ããã覧ãã ãã:
ãã¼ãªããä½è£ãªãã£ããªãã¨ãGSoCã®ææ³ã¿ãããªã®ã¯ã¾ãè½ã¡çãã¦ããæ¸ãããã¨æãã¾ãã
æ¦è¦
IRuby notebookä¸ã§åä½ãããplotã®ããã®gemã
ãããã¨ãã
ã¤ã³ã¿ã©ã¯ãã£ããª/ã¤ã³ã¿ã©ã¯ãã£ãã«plotãã§ããã
IRuby notebookä¸ã§å¯¾è©±çã«ãããããä½ããã¨ãã§ãã¾ããã¾ãæ¨æºã§ç¨æãããæ§ã ãªã¢ã¸ã¥ã¼ã«ãã¦ã¼ã¶ã¼ã®å¯¾è©±çãªæä½ãæ¯æ´ãã¾ãã
ä½ã£ãããããã¯SVGãWebGLã使ããã©ã¦ã¶ä¸ã«è¡¨ç¤ºã§ãããã¦ã¹ãã¿ããããã«ã§è§¦ãããã¨ãã§ãã¾ãã ãã®ä¾ã®ããã«è¤æ°ãã¤ã³éã§ãã¼ã¿ã®ãã£ã«ã¿ãªã³ã°ãè¡ããã¨ãã§ãã¾ãã
å ¬éãnotebookãDropboxãgistã«å¼µãä»ãã¦nbviewerã®ãªã³ã¯ãéãã ãã§ãã ãããªæãã§ã³ã¼ãã«markdownã§ç°¡åãªèª¬æãä»ãã¦gistã§å ¬éãã¿ãããªãã¨ãããã«ã§ãã¾ãã
è²ããªãããããã§ããã
åºæ¬çãª2Dã®ã°ã©ããã3Dãããã, å°å³ä¸ã§ã®ãããã, circos風ã®ç°ç¶ããããã¾ã§æ§ã ãªãã®ããã®gemã ãã§ä½ããã¨ãã§ãã¾ãã JavaScriptã¨Rubyã§ããã«æ¡å¼µãä½ããã®ã§JavaScriptã®æé¤ãããã°èªç±ã«ããããã追å ã§ãã¾ãã
使ãæ¹ãç°¡å
ç§æã§ããmatplotlibãBokehã®ãããªMATLAB風ã®APIãåããã½ããã¦ã§ã¢ã¯ãç°¡åãªããããã®ã¨ãã¯ããã®ã§ããã¡ãã£ã¨è¤éãªãããããä½ããã¨ããã¨è¡æ°ãççºããå¾åãããã¨æãã¾ãã Nyaplotã§ã¯ãã®ä¾ã®ããã«ãæ°è±¡ãã¼ã¿ã®å¯è¦åã®ãããªè¤éãªèª²é¡ã§ãããããé¨åã¯ãããæ°è¡ã§ãã¿ã¾ãã IRubyä¸ã§ã¯è£å®ãå¹ãã®ã§ãã¡ãã¡ä½¿ãæ¹ã調ã¹ãå¿ è¦ãããã¾ããã
使ãæ¹
gem install nyaplot
ã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ãã
gemã®ãã£ã¬ã¯ããªã®ä¸ã®examples/rb/*ã«ãµã³ãã«ã³ã¼ããããã¤ãå
¥ã£ã¦ããã®ã§å®è¡ããã¨ããããçµæãhtmlã§åºåããã¾ãã
Nyaplotåä½ã§ãåãã®ã§ãããIRuby notebookãä¸ç·ã«ã¤ã³ã¹ãã¼ã«ãããã¨ããå§ããã¾ãã IRubyã¯ãã©ã¦ã¶ä¸ã§åã対話çãªRubyã®å®è¡ç°å¢ã§ãNyaplotã¯IRubyä¸ã§åä½ããããã«è¨è¨ããã¦ãã¾ãã ä¸ã®åç»ãIRubyä¸ã§ã®åä½ãé²ç»ãããã®ã§ãã ã¤ã³ã¹ãã¼ã«æ¹æ³ãããç ©éãªã®ã§å¥éQiitaã«æ¸ããè¨äºãåèã«ãã¦ãã ããã
API(ä¸é¨)
以ä¸ã§ã¯Nyaplotã®æ©è½ã®ã»ãã®ä¸é¨ããç´¹ä»ãã¦ãã¾ããã詳ããã¯ãã¥ã¼ããªã¢ã«ã¨ããã¥ã¡ã³ããã覧ãã ããã
以ä¸ã®ã³ã¼ãã§æ£å¸å³ãä½ããã¨ãã§ãã¾ãã
plot = Nyaplot::Plot.new sc = plot.add(:scatter, [0,1,2,3,4], [-1,2,-3,4,-5]) plot.show
Nyaplot::Plotãããããã®åºæ¬ã¨ãªãã¯ã©ã¹ã§ãPlot#add
ã§æ°ããå³ã追å ã§ãã¾ããadd
ã¯Nyaplot::Diagram
ã®ã¤ã³ã¹ã¿ã³ã¹ãè¿ãããã®ãªãã¸ã§ã¯ããæã¤ã¡ã½ãããå¼ã³åºããã¨ã§å³ã®è¨å®ãå¤ãããã¨ãã§ãã¾ãã
ä¾ãã°è²ãå¤ããã«ã¯ä»¥ä¸ã®ãããªã³ã¼ããæ¸ãã¾ãã
color = Nyaplot::Colors.qual sc.color(color)
Colors.qual
ã¯è³ªç(qualitative)ãã¼ã¿ã®ããããã«æé©ãªè²ã®ã»ãããã©ã³ãã ã«è¿ãã¾ããIRubyä¸ãªãã°ä¸ã®ããã«ãã®å ´ã§è²ã確èªãããã¨ãã§ããä½åº¦ãå®è¡ãã¦å¥½ããªè²ãé¸æãããã¨ãã§ãã¾ãã
åºæ¥ä¸ãã£ãããããã¯ä»¥ä¸ã®ã³ã¼ãã§ç¢ºèªã§ãã¾ãã
Plot#export_html
ã«å¼æ°ã渡ãã¨åºåãããhtmlãã¡ã¤ã«ã®ååãæå®ãããã¨ãã§ãã¾ãã
plot.show # show plot on IRuby notebook plot.export_html # export plot to the current directory as a html file
ä¸ã®ãµã³ãã«ã¯ã¨ã¦ãã·ã³ãã«ãªãã®ã§ãããNyaplot::DataFrame
ã使ããã¨ã§ããè¤éãªãããããä½ããã¨ãã§ãã¾ãã
df = Nyaplot::DataFrame.new({a: [0,1,2,3,4], b: [-1,2,-3,4,-5], type: ['a','b','a','a','b']})
Plot#add_with_df
ã使ã£ã¦DataFrameãå
ã«ãããããä½ããã¨ãã§ãã¾ãã
Diagrams::Scatter#fill_by
ã®å¼æ°ã«è¡(column)ã®ååãæå®ãããã¨ã§ãã®è¡ã®å¤ã«ãããã£ã¦åç¹ã®è²ãå¡ãåãããã¨ãã§ãã¾ãã
sc = plot.add_with_df(df, :scatter, :a, :b) sc.fill_by(:type) plot.show
éæ
ããªã使ãããã¤ãªã®ã§æ¯éã試ããã ããã åé¡ãææ¡ãªã©ããã°GitHubã®Issueãpull-reqã§ãé¡ããã¾ãã