seaborn.stripplot


A strip plot is a scatter plot where one of the variables is categorical. They can be combined with other plots to provide additional information. For example, a boxplot with an overlaid strip plot becomes more similar to a violin plot because some additional information about how the underlying data is distributed becomes visible.

dataset:


In [66]:
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
plt.rcParams['figure.figsize'] = (20.0, 10.0)
plt.rcParams['font.family'] = "serif"

In [67]:
from sklearn import datasets
iris_data = datasets.load_iris()

In [68]:
df = pd.DataFrame(data=np.column_stack([iris_data['data'],iris_data['target']]),
                  columns=iris_data['feature_names'] + ['species'])

In [69]:
df['species'] = iris_data['target_names'][df.species.astype(int)]

Basic plot


In [126]:
p = sns.stripplot(data=df, x='species',y='sepal length (cm)',jitter=1,marker='^',hue='species')
handles,labels = p.get_legend_handles_labels()
for l in labels[:3]:
    
    l += " Sepal Length"
    print(l)
for l in labels[:3]:
    print(l)
plt.legend(handles, labels)
# sns.stripplot(data=df, x='species',y='sepal width (cm)',palette='magma',jitter=1,marker='s',hue='species')
# handles,labels = p.get_legend_handles_labels()
# # for h in handles[:2]:
# #     h.set_label(h.get_label() + " Sepal Length")
# # for h in handles[2:]:
# #     h.set_label(h.get_label() + " Sepal Width")

# for l in labels[2:]:
#     l+= " Sepal Width"
# plt.legend(handles, labels)


setosa Sepal Length
versicolor Sepal Length
virginica Sepal Length
setosa
versicolor
virginica
Out[126]:
<matplotlib.legend.Legend at 0x7fdfcda1d7b8>

In [89]:
#ns.stripplot(data=df, x='species',y='sepal length (cm)',jitter=1,marker='^',hue='species')
#sns.stripplot(data=df, x='species',y='sepal width (cm)',palette='magma',jitter=1,marker='^',hue='species')

In [150]:
fig, ax = plt.subplots(1,1)
p = sns.stripplot(data=df, x='species',y='sepal length (cm)',jitter=1,marker='^',hue='species',ax = ax)
handles,labels = ax.get_legend_handles_labels()
new_labels = []
for l in labels:
    new_labels.append(l.capitalize() + " Sepal Length")
plt.legend(handles, new_labels)


Out[150]:
<matplotlib.legend.Legend at 0x7fdfcd034780>

In [143]:
for i in labels:
    i=0
print(labels)


['setosa', 'versicolor', 'virginica']

In [109]:
plt.show()

In [100]:
dir(h[0])


Out[100]:
['_A',
 '__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_agg_filter',
 '_alpha',
 '_animated',
 '_antialiaseds',
 '_axes',
 '_bcast_lwls',
 '_clipon',
 '_clippath',
 '_contains',
 '_edge_default',
 '_edgecolors',
 '_facecolors',
 '_factor',
 '_get_bool',
 '_get_value',
 '_gid',
 '_hatch',
 '_hatch_color',
 '_is_filled',
 '_is_stroked',
 '_label',
 '_linestyles',
 '_linewidths',
 '_mouseover',
 '_offset_position',
 '_offsets',
 '_oid',
 '_original_edgecolor',
 '_original_facecolor',
 '_path_effects',
 '_paths',
 '_picker',
 '_pickradius',
 '_prepare_points',
 '_prop_order',
 '_propobservers',
 '_rasterized',
 '_remove_method',
 '_set_edgecolor',
 '_set_facecolor',
 '_set_gc_clip',
 '_sizes',
 '_sketch',
 '_snap',
 '_stale',
 '_sticky_edges',
 '_transOffset',
 '_transform',
 '_transformSet',
 '_transforms',
 '_uniform_offsets',
 '_url',
 '_urls',
 '_us_linestyles',
 '_us_lw',
 '_visible',
 'add_callback',
 'add_checker',
 'aname',
 'autoscale',
 'autoscale_None',
 'axes',
 'callbacksSM',
 'changed',
 'check_update',
 'clipbox',
 'cmap',
 'colorbar',
 'contains',
 'convert_xunits',
 'convert_yunits',
 'draw',
 'eventson',
 'figure',
 'findobj',
 'format_cursor_data',
 'get_agg_filter',
 'get_alpha',
 'get_animated',
 'get_array',
 'get_axes',
 'get_children',
 'get_clim',
 'get_clip_box',
 'get_clip_on',
 'get_clip_path',
 'get_cmap',
 'get_contains',
 'get_cursor_data',
 'get_dashes',
 'get_datalim',
 'get_edgecolor',
 'get_edgecolors',
 'get_facecolor',
 'get_facecolors',
 'get_figure',
 'get_fill',
 'get_gid',
 'get_hatch',
 'get_label',
 'get_linestyle',
 'get_linestyles',
 'get_linewidth',
 'get_linewidths',
 'get_offset_position',
 'get_offset_transform',
 'get_offsets',
 'get_path_effects',
 'get_paths',
 'get_picker',
 'get_pickradius',
 'get_rasterized',
 'get_sizes',
 'get_sketch_params',
 'get_snap',
 'get_transform',
 'get_transformed_clip_path_and_affine',
 'get_transforms',
 'get_url',
 'get_urls',
 'get_visible',
 'get_window_extent',
 'get_zorder',
 'have_units',
 'hitlist',
 'is_figure_set',
 'is_transform_set',
 'mouseover',
 'norm',
 'pchanged',
 'pick',
 'pickable',
 'properties',
 'remove',
 'remove_callback',
 'set',
 'set_agg_filter',
 'set_alpha',
 'set_animated',
 'set_antialiased',
 'set_antialiaseds',
 'set_array',
 'set_axes',
 'set_clim',
 'set_clip_box',
 'set_clip_on',
 'set_clip_path',
 'set_cmap',
 'set_color',
 'set_contains',
 'set_dashes',
 'set_edgecolor',
 'set_edgecolors',
 'set_facecolor',
 'set_facecolors',
 'set_figure',
 'set_gid',
 'set_hatch',
 'set_label',
 'set_linestyle',
 'set_linestyles',
 'set_linewidth',
 'set_linewidths',
 'set_lw',
 'set_norm',
 'set_offset_position',
 'set_offsets',
 'set_path_effects',
 'set_paths',
 'set_picker',
 'set_pickradius',
 'set_rasterized',
 'set_sizes',
 'set_sketch_params',
 'set_snap',
 'set_transform',
 'set_url',
 'set_urls',
 'set_visible',
 'set_zorder',
 'stale',
 'stale_callback',
 'sticky_edges',
 'to_rgba',
 'update',
 'update_dict',
 'update_from',
 'update_scalarmappable',
 'zorder']

In [102]:
h[3].get_label()


Out[102]:
'setosa'

In [ ]: