本文整理汇总了Python中sage.plot.colors.to_mpl_color函数的典型用法代码示例。如果您正苦于以下问题:Python to_mpl_color函数的具体用法?Python to_mpl_color怎么用?Python to_mpl_color使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_mpl_color函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
Render this ellipse in a subplot. This is the key function that
defines how this ellipse graphics primitive is rendered in matplotlib's
library.
TESTS::
sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3)
::
sage: ellipse((3,2),1,2)
"""
import matplotlib.patches as patches
options = self.options()
p = patches.Ellipse(
(self.x,self.y),
self.r1*2.,self.r2*2.,self.angle/pi*180.)
p.set_linewidth(float(options['thickness']))
p.set_fill(options['fill'])
a = float(options['alpha'])
p.set_alpha(a)
ec = to_mpl_color(options['edgecolor'])
fc = to_mpl_color(options['facecolor'])
if 'rgbcolor' in options:
ec = fc = to_mpl_color(options['rgbcolor'])
p.set_edgecolor(ec)
p.set_facecolor(fc)
p.set_linestyle(options['linestyle'])
z = int(options.pop('zorder', 0))
p.set_zorder(z)
subplot.add_patch(p)
示例2: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
TESTS::
sage: P = polygon([(0,0), (1,2), (0,1), (-1,2)])
"""
import matplotlib.patches as patches
options = self.options()
p = patches.Polygon([(self.xdata[i],self.ydata[i]) for i in xrange(len(self.xdata))])
p.set_linewidth(float(options['thickness']))
a = float(options['alpha'])
z = int(options.pop('zorder', 1))
p.set_alpha(a)
f = options.pop('fill')
p.set_fill(f)
c = to_mpl_color(options['rgbcolor'])
if f:
ec = options['edgecolor']
if ec is None:
p.set_color(c)
else:
p.set_facecolor(c)
p.set_edgecolor(to_mpl_color(ec))
else:
p.set_color(c)
p.set_label(options['legend_label'])
p.set_zorder(z)
subplot.add_patch(p)
示例3: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
TESTS::
sage: C = circle((2,pi), 2, edgecolor='black', facecolor='green', fill=True)
"""
import matplotlib.patches as patches
options = self.options()
p = patches.Circle((float(self.x), float(self.y)), float(self.r), clip_on=options['clip'])
if not options['clip']:
self._bbox_extra_artists=[p]
p.set_linewidth(float(options['thickness']))
p.set_fill(options['fill'])
a = float(options['alpha'])
p.set_alpha(a)
ec = to_mpl_color(options['edgecolor'])
fc = to_mpl_color(options['facecolor'])
if 'rgbcolor' in options:
ec = fc = to_mpl_color(options['rgbcolor'])
p.set_edgecolor(ec)
p.set_facecolor(fc)
p.set_linestyle(options['linestyle'])
p.set_label(options['legend_label'])
z = int(options.pop('zorder', 0))
p.set_zorder(z)
subplot.add_patch(p)
示例4: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
Render this line on a matplotlib subplot.
INPUT:
- ``subplot`` -- a matplotlib subplot
EXAMPLES:
This implicitly calls this function::
sage: line([(1,2), (3,-4), (2, 5), (1,2)])
"""
import matplotlib.lines as lines
options = dict(self.options())
del options['alpha']
del options['thickness']
del options['rgbcolor']
del options['legend_label']
if 'linestyle' in options:
del options['linestyle']
p = lines.Line2D(self.xdata, self.ydata, **options)
options = self.options()
a = float(options['alpha'])
p.set_alpha(a)
p.set_linewidth(float(options['thickness']))
p.set_color(to_mpl_color(options['rgbcolor']))
p.set_label(options['legend_label'])
# we don't pass linestyle in directly since the drawstyles aren't
# pulled off automatically. This (I think) is a bug in matplotlib 1.0.1
if 'linestyle' in options:
p.set_linestyle(options['linestyle'])
subplot.add_line(p)
示例5: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
TESTS::
sage: A = arc((1,1),3,4,pi/4,(pi,4*pi/3)); A
Graphics object consisting of 1 graphics primitive
"""
import matplotlib.patches as patches
from sage.plot.misc import get_matplotlib_linestyle
options = self.options()
p = patches.Arc(
(self.x,self.y),
2.*self.r1,
2.*self.r2,
fmod(self.angle,2*pi)*(180./pi),
self.s1*(180./pi),
self.s2*(180./pi))
p.set_linewidth(float(options['thickness']))
a = float(options['alpha'])
p.set_alpha(a)
z = int(options.pop('zorder',1))
p.set_zorder(z)
c = to_mpl_color(options['rgbcolor'])
p.set_linestyle(get_matplotlib_linestyle(options['linestyle'],return_type='long'))
p.set_edgecolor(c)
subplot.add_patch(p)
示例6: _render_on_subplot
def _render_on_subplot(self,subplot):
r"""
TESTS:
We check to make sure that \#2076 is fixed by verifying all
the points are red::
sage: point(((1,1), (2,2), (3,3)), rgbcolor=hue(1), size=30)
"""
options = self.options()
#Convert the color to a hex string so that the scatter
#method does not interpret it as a list of 3 floating
#point color specifications when there are
#three points. This is mentioned in the matplotlib 0.98
#documentation and fixes \#2076
from matplotlib.colors import rgb2hex
c = rgb2hex(to_mpl_color(options['rgbcolor']))
a = float(options['alpha'])
z = int(options.pop('zorder', 0))
s = int(options['size'])
faceted = options['faceted'] #faceted=True colors the edge of point
scatteroptions={}
if not faceted: scatteroptions['edgecolors'] = 'none'
subplot.scatter(self.xdata, self.ydata, s=s, c=c, alpha=a, zorder=z, label=options['legend_label'], **scatteroptions)
示例7: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
Render this line on a matplotlib subplot.
INPUT:
- ``subplot`` -- a matplotlib subplot
EXAMPLES:
This implicitly calls this function::
sage: line([(1,2), (3,-4), (2, 5), (1,2)])
Graphics object consisting of 1 graphics primitive
"""
import matplotlib.lines as lines
options = dict(self.options())
for o in ('alpha', 'legend_color', 'legend_label', 'linestyle',
'rgbcolor', 'thickness'):
if o in options:
del options[o]
p = lines.Line2D(self.xdata, self.ydata, **options)
options = self.options()
a = float(options['alpha'])
p.set_alpha(a)
p.set_linewidth(float(options['thickness']))
p.set_color(to_mpl_color(options['rgbcolor']))
p.set_label(options['legend_label'])
# we don't pass linestyle in directly since the drawstyles aren't
# pulled off automatically. This (I think) is a bug in matplotlib 1.0.1
if 'linestyle' in options:
from sage.plot.misc import get_matplotlib_linestyle
p.set_linestyle(get_matplotlib_linestyle(options['linestyle'],
return_type='short'))
subplot.add_line(p)
示例8: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
TESTS::
sage: A = arc((1,1),3,4,pi/4,(pi,4*pi/3)); A
"""
import matplotlib.patches as patches
options = self.options()
p = patches.Arc(
(self.x,self.y),
2.*self.r1,
2.*self.r2,
fmod(self.angle,2*pi)*(180./pi),
self.s1*(180./pi),
self.s2*(180./pi))
p.set_linewidth(float(options['thickness']))
a = float(options['alpha'])
p.set_alpha(a)
z = int(options.pop('zorder',1))
p.set_zorder(z)
c = to_mpl_color(options['rgbcolor'])
p.set_linestyle(options['linestyle'])
p.set_edgecolor(c)
subplot.add_patch(p)
示例9: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
Render this arrow in a subplot. This is the key function that
defines how this arrow graphics primitive is rendered in
matplotlib's library.
EXAMPLES::
This function implicitly ends up rendering this arrow on a matplotlib subplot:
sage: arrow(path=[[(0,1), (2,-1), (4,5)]])
"""
options = self.options()
width = float(options['width'])
head = options.pop('head')
if head == 0: style = '<|-'
elif head == 1: style = '-|>'
elif head == 2: style = '<|-|>'
else: raise KeyError('head parameter must be one of 0 (start), 1 (end) or 2 (both).')
arrowsize = float(options.get('arrowsize',5))
head_width=arrowsize
head_length=arrowsize*2.0
color = to_mpl_color(options['rgbcolor'])
from matplotlib.patches import FancyArrowPatch
from matplotlib.path import Path
bpath = Path(self.vertices, self.codes)
p = FancyArrowPatch(path=bpath,
lw=width, arrowstyle='%s,head_width=%s,head_length=%s'%(style,head_width, head_length),
fc=color, ec=color, linestyle=options['linestyle'])
p.set_zorder(options['zorder'])
p.set_label(options['legend_label'])
subplot.add_patch(p)
return p
示例10: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
TESTS::
sage: D = disk((2,-1), 2, (0, pi), color='black', thickness=3, fill=False); D
Save alpha information in pdf (see :trac:`13732`)::
sage: f = tmp_filename(ext='.pdf')
sage: p = disk((0,0), 5, (0, pi/4), alpha=0.5)
sage: p.save(f)
"""
import matplotlib.patches as patches
options = self.options()
deg1 = self.rad1*(180./pi) #convert radians to degrees
deg2 = self.rad2*(180./pi)
z = int(options.pop('zorder', 0))
p = patches.Wedge((float(self.x), float(self.y)), float(self.r), float(deg1),
float(deg2), zorder=z)
a = float(options['alpha'])
p.set_alpha(a)
p.set_linewidth(float(options['thickness']))
p.set_fill(options['fill'])
c = to_mpl_color(options['rgbcolor'])
p.set_edgecolor(c)
p.set_facecolor(c)
p.set_label(options['legend_label'])
subplot.add_patch(p)
示例11: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
Render this ellipse in a subplot. This is the key function that
defines how this ellipse graphics primitive is rendered in matplotlib's
library.
TESTS::
sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3)
Graphics object consisting of 1 graphics primitive
::
sage: ellipse((3,2),1,2)
Graphics object consisting of 1 graphics primitive
"""
import matplotlib.patches as patches
from sage.plot.misc import get_matplotlib_linestyle
options = self.options()
p = patches.Ellipse((self.x, self.y), self.r1 * 2.0, self.r2 * 2.0, self.angle / pi * 180.0)
p.set_linewidth(float(options["thickness"]))
p.set_fill(options["fill"])
a = float(options["alpha"])
p.set_alpha(a)
ec = to_mpl_color(options["edgecolor"])
fc = to_mpl_color(options["facecolor"])
if "rgbcolor" in options:
ec = fc = to_mpl_color(options["rgbcolor"])
p.set_edgecolor(ec)
p.set_facecolor(fc)
p.set_linestyle(get_matplotlib_linestyle(options["linestyle"], return_type="long"))
p.set_label(options["legend_label"])
z = int(options.pop("zorder", 0))
p.set_zorder(z)
subplot.add_patch(p)
示例12: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
Render this arrow in a subplot. This is the key function that
defines how this arrow graphics primitive is rendered in
matplotlib's library.
EXAMPLES::
This function implicitly ends up rendering this arrow on a matplotlib subplot:
sage: arrow(path=[[(0,1), (2,-1), (4,5)]])
Graphics object consisting of 1 graphics primitive
"""
from sage.plot.misc import get_matplotlib_linestyle
options = self.options()
width = float(options["width"])
head = options.pop("head")
if head == 0:
style = "<|-"
elif head == 1:
style = "-|>"
elif head == 2:
style = "<|-|>"
else:
raise KeyError("head parameter must be one of 0 (start), 1 (end) or 2 (both).")
arrowsize = float(options.get("arrowsize", 5))
head_width = arrowsize
head_length = arrowsize * 2.0
color = to_mpl_color(options["rgbcolor"])
from matplotlib.patches import FancyArrowPatch
from matplotlib.path import Path
bpath = Path(self.vertices, self.codes)
p = FancyArrowPatch(
path=bpath,
lw=width,
arrowstyle="%s,head_width=%s,head_length=%s" % (style, head_width, head_length),
fc=color,
ec=color,
)
p.set_linestyle(get_matplotlib_linestyle(options["linestyle"], return_type="long"))
p.set_zorder(options["zorder"])
p.set_label(options["legend_label"])
subplot.add_patch(p)
return p
示例13: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
Render this Bezier path in a subplot. This is the key function that
defines how this Bezier path graphics primitive is rendered in matplotlib's
library.
TESTS::
sage: bezier_path([[(0,1),(.5,0),(1,1)]])
Graphics object consisting of 1 graphics primitive
::
sage: bezier_path([[(0,1),(.5,0),(1,1),(-3,5)]])
Graphics object consisting of 1 graphics primitive
"""
from matplotlib.patches import PathPatch
from matplotlib.path import Path
from sage.plot.misc import get_matplotlib_linestyle
options = dict(self.options())
del options['alpha']
del options['thickness']
del options['rgbcolor']
del options['zorder']
del options['fill']
del options['linestyle']
bpath = Path(self.vertices, self.codes)
bpatch = PathPatch(bpath, **options)
options = self.options()
bpatch.set_linewidth(float(options['thickness']))
bpatch.set_fill(options['fill'])
bpatch.set_zorder(options['zorder'])
a = float(options['alpha'])
bpatch.set_alpha(a)
c = to_mpl_color(options['rgbcolor'])
bpatch.set_edgecolor(c)
bpatch.set_facecolor(c)
bpatch.set_linestyle(get_matplotlib_linestyle(options['linestyle'], return_type='long'))
subplot.add_patch(bpatch)
示例14: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
TESTS::
sage: D = disk((2,-1), 2, (0, pi), color='black', thickness=3, fill=False); D
"""
import matplotlib.patches as patches
options = self.options()
deg1 = self.rad1*(180./pi) #convert radians to degrees
deg2 = self.rad2*(180./pi)
z = int(options.pop('zorder', 0))
p = patches.Wedge((float(self.x), float(self.y)), float(self.r), float(deg1),
float(deg2), zorder=z)
p.set_linewidth(float(options['thickness']))
p.set_fill(options['fill'])
p.set_alpha(options['alpha'])
c = to_mpl_color(options['rgbcolor'])
p.set_edgecolor(c)
p.set_facecolor(c)
p.set_label(options['legend_label'])
subplot.add_patch(p)
示例15: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
TESTS::
sage: A = arc((1,1),3,4,pi/4,(pi,4*pi/3)); A
Graphics object consisting of 1 graphics primitive
"""
from sage.plot.misc import get_matplotlib_linestyle
options = self.options()
p = self._matplotlib_arc()
p.set_linewidth(float(options['thickness']))
a = float(options['alpha'])
p.set_alpha(a)
z = int(options.pop('zorder', 1))
p.set_zorder(z)
c = to_mpl_color(options['rgbcolor'])
p.set_linestyle(get_matplotlib_linestyle(options['linestyle'],
return_type='long'))
p.set_edgecolor(c)
subplot.add_patch(p)