<Python, seaborn, matplotlib> 散布図の各要素に文字を付ける(seabornの場合)。

seabornの場合。

In [1]: import seaborn as sns

In [2]: import pandas as pd

In [3]: df = pd.DataFrame({'X':[1,2,3],'Y':[1,2,3],'A':['a','b','c']})

In [4]: g = sns.lmplot('X','Y',data=df)
   ...: for k, v in df.iterrows():
   ...:     g.ax.annotate(v['A'], xy=(v['X'],v['Y']), size=20)

f:id:nekoyukimmm:20151009092235p:plain

gアトリビュートattributeaxがあるんだね。ふーん。

ちなみに、gのタイプ

In [18]: type(g)
Out[18]: seaborn.axisgrid.FacetGrid

あと、gが持っている関数他

In [20]: dir(g)
Out[20]: 
['__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_bottom_axes',
 '_clean_axis',
 '_col_var',
 '_col_wrap',
 '_colors',
 '_dropna',
 '_facet_color',
 '_facet_plot',
 '_finalize_grid',
 '_get_palette',
 '_hue_var',
 '_inner_axes',
 '_left_axes',
 '_legend',
 '_legend_data',
 '_legend_out',
 '_margin_titles',
 '_n_facets',
 '_ncol',
 '_not_bottom_axes',
 '_not_left_axes',
 '_not_na',
 '_nrow',
 '_row_var',
 '_update_legend_data',
 '_x_var',
 '_y_var',
 'add_legend',
 'ax',
 'axes',
 'col_names',
 'data',
 'despine',
 'facet_axis',
 'facet_data',
 'fig',
 'hue_kws',
 'hue_names',
 'map',
 'map_dataframe',
 'row_names',
 'savefig',
 'set',
 'set_axis_labels',
 'set_titles',
 'set_xlabels',
 'set_xticklabels',
 'set_ylabels',
 'set_yticklabels']