#!/usr/bin/env python # coding: utf-8 # [대한민국 SNS 이용현황](http://m.blog.naver.com/mobidays01/220331132165) 블로그 글에 표시된 그림을 좀 다르게 그려보자 # # ![](http://mblogthumb1.phinf.naver.net/20150414_20/mobidays01_14290006372183j5KB_JPEG/mobidays_sns%C0%CC%BF%EB%C7%F6%C8%B2.jpg?type=w2) # In[29]: get_ipython().run_line_magic('matplotlib', 'inline') # In[1]: import pandas as pd # In[89]: get_ipython().system('cat korean_social_networks.csv') # In[36]: data = pd.read_csv("korean_social_networks.csv", index_col=0) # In[37]: data # In[38]: columns = ['10s', '20s', '30s', '40s', '50s'] def calculate_real(row): return pd.Series([int(row[col] * row['mau']) for col in target_columns], index=columns) data[columns] = data.apply(calculate_real, axis=1) # In[39]: data # In[86]: data[columns].plot(kind="barh", stacked=True, figsize=(8,4), title="By services") # In[88]: data[columns].T.plot(kind="barh", stacked=True, figsize=(8, 4), title="By ages").legend(loc='center right', bbox_to_anchor=(1.3,0.5)) # In[ ]: