本文整理汇总了Python中sage.plot.misc.get_matplotlib_linestyle函数的典型用法代码示例。如果您正苦于以下问题:Python get_matplotlib_linestyle函数的具体用法?Python get_matplotlib_linestyle怎么用?Python get_matplotlib_linestyle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_matplotlib_linestyle函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _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)
示例2: _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
from sage.plot.misc import get_matplotlib_linestyle
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(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)
示例3: _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)]])
"""
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
示例4: _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)
示例5: _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
示例6: __init__
def __init__(self, datalist, options):
"""
Initialize a ``Histogram`` primitive along with
its options.
EXAMPLES::
sage: from sage.plot.histogram import Histogram
sage: Histogram([10,3,5], {'width':0.7})
Histogram defined by a data list of size 3
"""
import numpy as np
self.datalist=np.asarray(datalist,dtype=float)
if 'linestyle' in options:
from sage.plot.misc import get_matplotlib_linestyle
options['linestyle'] = get_matplotlib_linestyle(
options['linestyle'], return_type='long')
GraphicPrimitive.__init__(self, options)
示例7: _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)
示例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
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)
示例9: _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.,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(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)
示例10: _render_on_subplot
def _render_on_subplot(self, subplot):
"""
TESTS:
A somewhat random plot, but fun to look at::
sage: x,y = var('x,y')
sage: contour_plot(x^2-y^3+10*sin(x*y), (x, -4, 4), (y, -4, 4),plot_points=121,cmap='hsv')
"""
from sage.rings.integer import Integer
options = self.options()
fill = options['fill']
contours = options['contours']
if options.has_key('cmap'):
cmap = get_cmap(options['cmap'])
elif fill or contours is None:
cmap = get_cmap('gray')
else:
if isinstance(contours, (int, Integer)):
cmap = get_cmap([(i,i,i) for i in xsrange(0,1,1/contours)])
else:
l = Integer(len(contours))
cmap = get_cmap([(i,i,i) for i in xsrange(0,1,1/l)])
x0,x1 = float(self.xrange[0]), float(self.xrange[1])
y0,y1 = float(self.yrange[0]), float(self.yrange[1])
if isinstance(contours, (int, Integer)):
contours = int(contours)
CSF=None
if fill:
if contours is None:
CSF=subplot.contourf(self.xy_data_array, cmap=cmap, extent=(x0,x1,y0,y1), label=options['legend_label'])
else:
CSF=subplot.contourf(self.xy_data_array, contours, cmap=cmap, extent=(x0,x1,y0,y1),extend='both', label=options['legend_label'])
linewidths = options.get('linewidths',None)
if isinstance(linewidths, (int, Integer)):
linewidths = int(linewidths)
elif isinstance(linewidths, (list, tuple)):
linewidths = tuple(int(x) for x in linewidths)
from sage.plot.misc import get_matplotlib_linestyle
linestyles = options.get('linestyles', None)
if isinstance(linestyles, (list, tuple)):
linestyles = [get_matplotlib_linestyle(l, 'long') for l in linestyles]
else:
linestyles = get_matplotlib_linestyle(linestyles, 'long')
if contours is None:
CS = subplot.contour(self.xy_data_array, cmap=cmap, extent=(x0,x1,y0,y1),
linewidths=linewidths, linestyles=linestyles, label=options['legend_label'])
else:
CS = subplot.contour(self.xy_data_array, contours, cmap=cmap, extent=(x0,x1,y0,y1),
linewidths=linewidths, linestyles=linestyles, label=options['legend_label'])
if options.get('labels', False):
label_options = options['label_options']
label_options['fontsize'] = int(label_options['fontsize'])
if fill and label_options is None:
label_options['inline']=False
subplot.clabel(CS, **label_options)
if options.get('colorbar', False):
colorbar_options = options['colorbar_options']
from matplotlib import colorbar
cax,kwds=colorbar.make_axes_gridspec(subplot,**colorbar_options)
if CSF is None:
cb=colorbar.Colorbar(cax,CS, **kwds)
else:
cb=colorbar.Colorbar(cax,CSF, **kwds)
cb.add_lines(CS)
示例11: _render_on_subplot
def _render_on_subplot(self, subplot):
r"""
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((0,1), (2,-1))
TESTS:
The length of the ends (shrinkA and shrinkB) should not depend
on the width of the arrow, because Matplotlib already takes
this into account. See :trac:`12836`::
sage: fig = Graphics().matplotlib()
sage: sp = fig.add_subplot(1,1,1)
sage: a = arrow((0,0), (1,1))
sage: b = arrow((0,0), (1,1), width=20)
sage: p1 = a[0]._render_on_subplot(sp)
sage: p2 = b[0]._render_on_subplot(sp)
sage: p1.shrinkA == p2.shrinkA
True
sage: p1.shrinkB == p2.shrinkB
True
Dashed arrows should have solid arrowheads,
:trac:`12852`. This test saves the plot of a dashed arrow to
an EPS file. Within the EPS file, ``stroke`` will be called
twice: once to draw the line, and again to draw the
arrowhead. We check that both calls do not occur while the
dashed line style is enabled::
sage: a = arrow((0,0), (1,1), linestyle='dashed')
sage: filename = tmp_filename(ext='.eps')
sage: a.save(filename=filename)
sage: with open(filename, 'r') as f:
....: contents = f.read().replace('\n', ' ')
sage: two_stroke_pattern = r'setdash.*stroke.*stroke.*setdash'
sage: import re
sage: two_stroke_re = re.compile(two_stroke_pattern)
sage: two_stroke_re.search(contents) is None
True
"""
from sage.plot.misc import get_matplotlib_linestyle
options = self.options()
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).")
width = float(options["width"])
arrowshorten_end = float(options.get("arrowshorten", 0)) / 2.0
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
p = FancyArrowPatch(
(self.xtail, self.ytail),
(self.xhead, self.yhead),
lw=width,
arrowstyle="%s,head_width=%s,head_length=%s" % (style, head_width, head_length),
shrinkA=arrowshorten_end,
shrinkB=arrowshorten_end,
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"])
if options["linestyle"] != "solid":
# The next few lines work around a design issue in matplotlib. Currently, the specified
# linestyle is used to draw both the path and the arrowhead. If linestyle is 'dashed', this
# looks really odd. This code is from Jae-Joon Lee in response to a post to the matplotlib mailing
# list. See http://sourceforge.net/mailarchive/forum.php?thread_name=CAG%3DuJ%2Bnw2dE05P9TOXTz_zp-mGP3cY801vMH7yt6vgP9_WzU8w%40mail.gmail.com&forum_name=matplotlib-users
import matplotlib.patheffects as pe
class CheckNthSubPath(object):
def __init__(self, patch, n):
"""
creates an callable object that returns True if the provided
path is the n-th path from the patch.
"""
self._patch = patch
self._n = n
def get_paths(self, renderer):
#.........这里部分代码省略.........
示例12: set_edges
def set_edges(self, **edge_options):
"""
Sets the edge (or arrow) plotting parameters for the ``GraphPlot`` object.
This function is called by the constructor but can also be called to make
updates to the vertex options of an existing ``GraphPlot`` object. Note
that the changes are cumulative.
EXAMPLES::
sage: g = Graph({}, loops=True, multiedges=True, sparse=True)
sage: g.add_edges([(0,0,'a'),(0,0,'b'),(0,1,'c'),(0,1,'d'),
... (0,1,'e'),(0,1,'f'),(0,1,'f'),(2,1,'g'),(2,2,'h')])
sage: GP = g.graphplot(vertex_size=100, edge_labels=True, color_by_label=True, edge_style='dashed')
sage: GP.set_edges(edge_style='solid')
sage: GP.plot()
Graphics object consisting of 22 graphics primitives
sage: GP.set_edges(edge_color='black')
sage: GP.plot()
Graphics object consisting of 22 graphics primitives
sage: d = DiGraph({}, loops=True, multiedges=True, sparse=True)
sage: d.add_edges([(0,0,'a'),(0,0,'b'),(0,1,'c'),(0,1,'d'),
... (0,1,'e'),(0,1,'f'),(0,1,'f'),(2,1,'g'),(2,2,'h')])
sage: GP = d.graphplot(vertex_size=100, edge_labels=True, color_by_label=True, edge_style='dashed')
sage: GP.set_edges(edge_style='solid')
sage: GP.plot()
Graphics object consisting of 24 graphics primitives
sage: GP.set_edges(edge_color='black')
sage: GP.plot()
Graphics object consisting of 24 graphics primitives
TESTS::
sage: G = Graph("Fooba")
sage: G.show(edge_colors={'red':[(3,6),(2,5)]})
Verify that default edge labels are pretty close to being between the vertices
in some cases where they weren't due to truncating division (:trac:`10124`)::
sage: test_graphs = graphs.FruchtGraph(), graphs.BullGraph()
sage: tol = 0.001
sage: for G in test_graphs:
... E=G.edges()
... for e0, e1, elab in E:
... G.set_edge_label(e0, e1, '%d %d' % (e0, e1))
... gp = G.graphplot(save_pos=True,edge_labels=True)
... vx = gp._plot_components['vertices'][0].xdata
... vy = gp._plot_components['vertices'][0].ydata
... for elab in gp._plot_components['edge_labels']:
... textobj = elab[0]
... x, y, s = textobj.x, textobj.y, textobj.string
... v0, v1 = map(int, s.split())
... vn = vector(((x-(vx[v0]+vx[v1])/2.),y-(vy[v0]+vy[v1])/2.)).norm()
... assert vn < tol
"""
for arg in edge_options:
self._options[arg] = edge_options[arg]
if 'edge_colors' in edge_options: self._options['color_by_label'] = False
# Handle base edge options: thickness, linestyle
eoptions={}
if 'edge_style' in self._options:
from sage.plot.misc import get_matplotlib_linestyle
eoptions['linestyle'] = get_matplotlib_linestyle(
self._options['edge_style'],
return_type='long')
if 'thickness' in self._options:
eoptions['thickness'] = self._options['thickness']
# Set labels param to add labels on the fly
labels = False
if self._options['edge_labels']:
labels = True
self._plot_components['edge_labels'] = []
# Make dict collection of all edges (keep label and edge color)
edges_to_draw = {}
if self._options['color_by_label'] or isinstance(self._options['edge_colors'], dict):
if self._options['color_by_label']:
edge_colors = self._graph._color_by_label(format=self._options['color_by_label'])
else: edge_colors = self._options['edge_colors']
for color in edge_colors:
for edge in edge_colors[color]:
key = tuple(sorted([edge[0],edge[1]]))
if key == (edge[0],edge[1]): head = 1
else: head = 0
if len(edge) < 3:
label = self._graph.edge_label(edge[0],edge[1])
if isinstance(label, list):
if key in edges_to_draw:
edges_to_draw[key].append((label[-1], color, head))
else:
edges_to_draw[key] = [(label[-1], color, head)]
for i in range(len(label)-1):
edges_to_draw[key].append((label[-1], color, head))
else:
label = edge[2]
#.........这里部分代码省略.........