Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
93 lines (73 loc) · 2.85 KB
/
Copy pathutils.py
File metadata and controls
93 lines (73 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-
###############################################################################
#
# Copyright (C) 2015-2020 Daniel Rodriguez
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from colorsys import rgb_to_hls as rgb2hls, hls_to_rgb as hls2rgb
import matplotlib.colors as mplcolors
import matplotlib.path as mplpath
def tag_box_style(x0, y0, width, height, mutation_size, mutation_aspect=1):
"""
Given the location and size of the box, return the path of
the box around it.
- *x0*, *y0*, *width*, *height* : location and size of the box
- *mutation_size* : a reference scale for the mutation.
- *aspect_ratio* : aspect-ration for the mutation.
"""
# note that we are ignoring mutation_aspect. This is okay in general.
mypad = 0.2
pad = mutation_size * mypad
# width and height with padding added.
width, height = width + 2.*pad, height + 2.*pad,
# boundary of the padded box
x0, y0 = x0-pad, y0-pad,
x1, y1 = x0+width, y0 + height
cp = [(x0, y0),
(x1, y0), (x1, y1), (x0, y1),
(x0-pad, (y0+y1)/2.), (x0, y0),
(x0, y0)]
com = [mplpath.Path.MOVETO,
mplpath.Path.LINETO, mplpath.Path.LINETO, mplpath.Path.LINETO,
mplpath.Path.LINETO, mplpath.Path.LINETO,
mplpath.Path.CLOSEPOLY]
path = mplpath.Path(cp, com)
return path
def shade_color(color, percent):
"""Shade Color
This color utility function allows the user to easily darken or
lighten a color for plotting purposes.
Parameters
----------
color : string, list, hexvalue
Any acceptable Matplotlib color value, such as
'red', 'slategrey', '#FFEE11', (1,0,0)
percent : the amount by which to brighten or darken the color.
Returns
-------
color : tuple of floats
tuple representing converted rgb values
"""
rgb = mplcolors.colorConverter.to_rgb(color)
h, l, s = rgb2hls(*rgb)
l *= 1 + float(percent)/100
l = min(1, l)
l = max(0, l)
r, g, b = hls2rgb(h, l, s)
return r, g, b