Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _draw_segments(data, ax, **params):
"""
Draw independent line segments between all the
points
"""
color = to_rgba(data['color'], data['alpha'])
# All we do is line-up all the points in a group
# into segments, all in a single list.
# Along the way the other parameters are put in
# sequences accordingly
indices = [] # for attributes of starting point of each segment
segments = []
for _, df in data.groupby('group'):
idx = df.index
indices.extend(idx[:-1]) # One line from two points
x = data['x'].iloc[idx]
y = data['y'].iloc[idx]
segments.append(make_line_segments(x, y, ispath=True))
segments = np.vstack(segments)
if color is None:
def _draw_lines(data, ax, **params):
"""
Draw a path with the same characteristics from the
first point to the last point
"""
color = to_rgba(data['color'].iloc[0], data['alpha'].iloc[0])
join_style = _get_joinstyle(data, params)
lines = mlines.Line2D(data['x'],
data['y'],
color=color,
linewidth=data['size'].iloc[0],
linestyle=data['linetype'].iloc[0],
zorder=params['zorder'],
**join_style)
ax.add_artist(lines)
def draw_group(data, panel_params, coord, ax, **params):
data = coord.transform(data, panel_params)
# Bind color and alpha
color = to_rgba(data['color'], data['alpha'])
# Create a dataframe for the plotting data required
# by ax.text
df = data[['x', 'y', 'size']].copy()
df['s'] = data['label']
df['rotation'] = data['angle']
df['linespacing'] = data['lineheight']
df['color'] = color
df['ha'] = data['ha']
df['va'] = data['va']
df['family'] = params['family']
df['fontweight'] = params['fontweight']
df['fontstyle'] = params['fontstyle']
df['zorder'] = params['zorder']
df['clip_on'] = True
def draw_group(data, panel_params, coord, ax, **params):
data = coord.transform(data, panel_params)
fill = to_rgba(data['fill'], data['alpha'])
color = to_rgba(data['color'], data['alpha'])
ranges = coord.range(panel_params)
# For perfect circles the width/height of the circle(ellipse)
# should factor in the dimensions of axes
bbox = ax.get_window_extent().transformed(
ax.figure.dpi_scale_trans.inverted())
ax_width, ax_height = bbox.width, bbox.height
factor = ((ax_width/ax_height) *
np.ptp(ranges.y)/np.ptp(ranges.x))
size = data.loc[0, 'binwidth'] * params['dotsize']
offsets = data['stackpos'] * params['stackratio']
if params['binaxis'] == 'x':
width, height = size, size*factor
xpos, ypos = data['x'], data['y'] + height*offsets
def draw_group(data, panel_params, coord, ax, **params):
data = coord.transform(data, panel_params)
data['size'] *= SIZE_FACTOR
color = to_rgba(data['color'], data['alpha'])
# start point -> end point, sequence of xy points
# from which line segments are created
x = interleave(data['x'], data['xend'])
y = interleave(data['y'], data['yend'])
segments = make_line_segments(x, y, ispath=False)
coll = mcoll.LineCollection(segments,
edgecolor=color,
linewidth=data['size'],
linestyle=data['linetype'][0],
zorder=params['zorder'])
ax.add_collection(coll)
if 'arrow' in params and params['arrow']:
adata = pd.DataFrame(index=range(len(data)*2))
idx = np.arange(1, len(data)+1)
def draw_group(data, panel_params, coord, ax, **params):
data = coord.transform(data, panel_params, munch=True)
data['size'] *= SIZE_FACTOR
verts = [None] * len(data)
limits = zip(data['xmin'], data['xmax'],
data['ymin'], data['ymax'])
for i, (l, r, b, t) in enumerate(limits):
verts[i] = [(l, b), (l, t), (r, t), (r, b)]
fill = to_rgba(data['fill'], data['alpha'])
color = data['color']
# prevent unnecessary borders
if all(color.isnull()):
color = 'none'
col = PolyCollection(
verts,
facecolors=fill,
edgecolors=color,
linestyles=data['linetype'],
linewidths=data['size'],
transOffset=ax.transData,
zorder=params['zorder'])
ax.add_collection(col)
def apply(self, ax):
super(panel_border, self).apply(ax)
d = deepcopy(self.properties)
# Be lenient, if using element_line
with suppress(KeyError):
d['edgecolor'] = d.pop('color')
with suppress(KeyError):
del d['facecolor']
if 'edgecolor' in d and 'alpha' in d:
d['edgecolor'] = to_rgba(d['edgecolor'], d['alpha'])
del d['alpha']
ax.patch.set(**d)
# Each group is a polygon with a single facecolor
# with potentially an edgecolor for every edge.
ngroups = data['group'].unique().size
verts = [None] * ngroups
facecolor = [None] * ngroups
edgecolor = [None] * ngroups
linestyle = [None] * ngroups
linewidth = [None] * ngroups
# Some stats may order the data in ways that prevent
# objects from occluding other objects. We do not want
# to undo that order.
grouper = data.groupby('group', sort=False)
for i, (group, df) in enumerate(grouper):
verts[i] = tuple(zip(df['x'], df['y']))
fill = to_rgba(df['fill'].iloc[0], df['alpha'].iloc[0])
facecolor[i] = 'none' if fill is None else fill
edgecolor[i] = df['color'].iloc[0] or 'none'
linestyle[i] = df['linetype'].iloc[0]
linewidth[i] = df['size'].iloc[0]
col = PolyCollection(
verts,
facecolors=facecolor,
edgecolors=edgecolor,
linestyles=linestyle,
linewidths=linewidth,
transOffset=ax.transData,
zorder=params['zorder'])
ax.add_collection(col)
x = np.repeat(data['x'].values, 2)
y = np.tile([ymax-yheight, ymax], n)
rugs.extend(make_line_segments(x, y, ispath=False))
if has_y:
if 'l' in sides:
x = np.tile([xmin, xmin+xheight], n)
y = np.repeat(data['y'].values, 2)
rugs.extend(make_line_segments(x, y, ispath=False))
if 'r' in sides:
x = np.tile([xmax-xheight, xmax], n)
y = np.repeat(data['y'].values, 2)
rugs.extend(make_line_segments(x, y, ispath=False))
color = to_rgba(data['color'], data['alpha'])
coll = mcoll.LineCollection(rugs,
edgecolor=color,
linewidth=data['size'],
linestyle=data['linetype'],
zorder=params['zorder'])
ax.add_collection(coll)