Python, pandas, ggplot-likeをオンにする時、はまったのでメモ
ggplot
のような感じのグラフを作る。
 
In [1]: import pandas as pd In [2]: import matplotlib.pyplot as plt In [3]: df = pd.DataFrame([(1,2),(3,4)]) In [4]: df.plot() Out[4]: <matplotlib.axes._subplots.AxesSubplot at 0x2b50f7a91048> In [5]: plt.show()
ということで、plt.show()
が効く。
で、、ggplot
をオンにする。
2つやり方があり、、、
その1
In [6]: pd.options.display.mpl_style = 'default' In [7]: df.plot() Out[7]: <matplotlib.axes._subplots.AxesSubplot at 0x2b50f8534a20>
pd.options.display.mpl_style='default'
でやると、df.plot()
でいきなりグラフが開く。
なんかplt.show()
の分までやってしまう感じらしい。。。 うまくない。
もう1つは、
In [9]: pd.options.display.mpl_style = None
で一旦戻しておいて、
In [13]: import matplotlib as mpl In [14]: mpl.style.available Out[14]: ['bmh', 'fivethirtyeight', 'grayscale', 'dark_background', 'ggplot'] In [15]: mpl.style.use('ggplot')
こうしておくと、
In [16]: df.plot() Out[16]: <matplotlib.axes._subplots.AxesSubplot at 0x2b50f875aef0> In [17]: plt.show()
でplt.show()
が効く。
めでたしめでたし。