Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Violin Element #2114

merged 18 commits into from Feb 5, 2018
Changes from 1 commit
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

Draw miniature boxplot inside mpl violinplot

  • Loading branch information
philippjfr committed Jan 29, 2018
commit 2d22074b73b2897c6be15d00aec30fed8d116461
@@ -281,5 +281,4 @@ def grid_selector(grid):
# Statistics
options.Distribution = Options('style', facecolor=Cycle(), edgecolor='black',
options.Violin = Options('style', facecolors=Cycle(), bw_method='scott',
showmedians=True, showextrema=False, alpha=0.7)
options.Violin = Options('style', facecolors=Cycle(), showextrema=False, alpha=0.7)
@@ -122,19 +122,43 @@ class ViolinPlot(BoxPlot):
plot option.

bandwidth = param.Number(default=None, doc="""
Allows supplying explicit bandwidth value rather than relying
on scott or silverman method.""")

inner = param.ObjectSelector(objects=['box', 'medians', None],
default='box', doc="""
Inner visual indicator for distribution values:
* box - A small box plot
* stick - Lines indicating each sample value
* quartiles - Indicates first, second and third quartiles

_plot_methods = dict(single='violinplot')

style_opts = ['showmedians', 'showmeans', 'facecolors',
'showextrema', 'bw_method', 'widths',
'stats_color', 'alpha', 'edgecolors']
style_opts = ['showmeans', 'facecolors', 'showextrema', 'bw_method',
'widths', 'stats_color', 'box_color', 'alpha', 'edgecolors']

def init_artists(self, ax, plot_args, plot_kwargs):
box_color = plot_kwargs.pop('box_color', 'black')
stats_color = plot_kwargs.pop('stats_color', 'black')
facecolors = plot_kwargs.pop('facecolors', [])
edgecolors = plot_kwargs.pop('edgecolors', 'black')
labels = plot_kwargs.pop('labels')
alpha = plot_kwargs.pop('alpha', 1.)
artists = super(ViolinPlot, self).init_artists(ax, plot_args, plot_kwargs)
artist = artists['artist']
showmedians = self.inner == 'medians'
bw_method = self.bandwidth or 'scott'
artist = ax.violinplot(*plot_args, bw_method=bw_method,
showmedians=showmedians, **plot_kwargs)
artists = {'artist': artist}
if self.inner == 'box':
box = ax.boxplot(*plot_args, positions=plot_kwargs['positions'],
showfliers=False, showcaps=False, patch_artist=True,
boxprops={'facecolor': box_color},
medianprops={'color': 'white'}, widths=0.1,
artists['box'] = box
for body, color in zip(artist['bodies'], facecolors):
@@ -160,10 +184,19 @@ def get_data(self, element, ranges, style):
colors.append(elstyle[i].get('facecolors', 'blue'))
style['positions'] = range(len(data))
style['labels'] = labels
style['facecolors'] = colors
style = {k: v for k, v in style.items()
if k not in ['zorder', 'label']}
style['vert'] = not self.invert_axes
format_kdims = [kd(value_format=None) for kd in element.kdims]
ticks = {'yticks' if self.invert_axes else 'xticks': list(enumerate(labels))}
return (data,), style, {'dimensions': [format_kdims, element.vdims[0]], **ticks}

def teardown_handles(self):
for group in self.handles['artist'].values():
for v in group:
for group in self.handles['box'].values():
for v in group:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.