本文整理汇总了Python中matplotlib.artist.setp函数的典型用法代码示例。如果您正苦于以下问题:Python setp函数的具体用法?Python setp怎么用?Python setp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: colorcycle
def colorcycle(index=None, handles=None):
'''Return a list of colors used for new lines in the axis.
index -- optional integer index for a color from the cycle
Return complete colorcycle when None. Return a single
color when integer. Return a list of colors when
iterable.
handles -- optional matplotlib object or iterable of objects, whose
color would be set according to the index.
Return string or a list of strings.
'''
from matplotlib import rcParams
ccycle = rcParams['axes.color_cycle'][:]
if index is None:
rv = ccycle
elif _isiterablenotstring(index):
rv = [colorcycle(i) for i in index]
else:
nmidx = index % len(ccycle)
rv = ccycle[nmidx]
if handles is not None:
from matplotlib.artist import setp
if type(rv) is list:
for c, h in zip(rv, handles):
setp(h, color=c)
else:
setp(handles, color=rv)
_redraw()
return rv
示例2: __init__
def __init__(self,
edgecolor=None,
facecolor=None,
linewidth=None,
linestyle=None,
antialiased = None,
hatch = None,
fill=True,
**kwargs
):
"""
The following kwarg properties are supported
%(Patch)s
"""
artist.Artist.__init__(self)
if linewidth is None: linewidth = mpl.rcParams['patch.linewidth']
if linestyle is None: linestyle = "solid"
if antialiased is None: antialiased = mpl.rcParams['patch.antialiased']
self.set_edgecolor(edgecolor)
self.set_facecolor(facecolor)
self.set_linewidth(linewidth)
self.set_linestyle(linestyle)
self.set_antialiased(antialiased)
self.set_hatch(hatch)
self.fill = fill
self._combined_transform = transforms.IdentityTransform()
if len(kwargs): artist.setp(self, **kwargs)
示例3: grid
def grid(self, b=None, which='major', axis="both", **kwargs):
"""
Toggle the gridlines, and optionally set the properties of the lines.
"""
# their are some discrepancy between the behavior of grid in
# axes_grid and the original mpl's grid, because axes_grid
# explicitly set the visibility of the gridlines.
super(Axes, self).grid(b, which=which, axis=axis, **kwargs)
if not self._axisline_on:
return
if b is None:
if self.axes.xaxis._gridOnMinor or self.axes.xaxis._gridOnMajor or \
self.axes.yaxis._gridOnMinor or self.axes.yaxis._gridOnMajor:
b=True
else:
b=False
self.gridlines.set_which(which)
self.gridlines.set_axis(axis)
self.gridlines.set_visible(b)
if len(kwargs):
martist.setp(self.gridlines, **kwargs)
示例4: _matplotlib_week_axis_setup
def _matplotlib_week_axis_setup(self, ax, xmin, xmax, ymin, ymax):
from matplotlib.dates import DayLocator, DateFormatter
from matplotlib.artist import setp
# X axis
ax.set_xlim((xmin, xmax))
ax.xaxis.set_major_locator(DayLocator())
ax.xaxis.set_major_formatter(DateFormatter("%a"))
ax.xaxis.grid(True, "major") # XXX - linestyle...
labels = ax.get_xticklabels()
setp(labels, rotation=0, fontsize=9)
for i in labels:
i.set_horizontalalignment('left')
# Y axis
ax.set_ylim((ymin, ymax))
yrange = range(ymin, ymax + 1)
yticks = []
ylabels = []
# Y tick and label generation is a bit fussy - the intent here is to generate
# a reasonable set of ticks and labels for various ymax values. The logic
# below works reasonably well for graph height ~100 pixels and ymax from 0 to
# several thousand.
tickstep = 5 # for large values, steps of 5 are odd (e.g. 35, 70, 105)
if ymax > 50:
tickstep = 10
if ymax > 500:
tickstep = 100
tickinterval = (ymax + 9) / 10 # roughly most 10 ticks per small image
if tickinterval > 1: # if step > 1, round up to nearest tickstep
tickinterval = (tickinterval + tickstep - 1) / tickstep * tickstep
if tickinterval <= 1:
tickinterval = 1 # otherwise use step 1 (also handles zero div)
labelinterval = (ymax + 2) / 3 # roughly 3 labels per small image
labelinterval = (labelinterval + tickstep - 1) / tickstep * tickstep # round up to nearest tickstep
labelinterval = (labelinterval + tickinterval - 1) / tickinterval * tickinterval # must be a multiple of tick interval!
if labelinterval <= 0:
labelinterval = tickinterval # sanity
if labelinterval <= 1:
labelinterval = 1
ymax_rounded = (ymax + labelinterval - 1) / labelinterval * labelinterval + tickinterval
# compute actual tick positions and labels
for i in range(ymin, ymax_rounded + 1, tickinterval):
yticks.append(i)
if (int(i) % labelinterval) == 0:
ylabels.append(str(int(i)))
else:
ylabels.append('')
ax.yaxis.set_ticks(yticks)
ax.yaxis.set_ticklabels(ylabels)
labels = ax.get_yticklabels()
setp(labels, rotation=0, fontsize=9)
示例5: _set_ticks_labels
def _set_ticks_labels(ax, data, labels, positions, plot_opts):
"""Set ticks and labels on horizontal axis."""
# Set xticks and limits.
ax.set_xlim([np.min(positions) - 0.5, np.max(positions) + 0.5])
ax.set_xticks(positions)
label_fontsize = plot_opts.get('label_fontsize')
label_rotation = plot_opts.get('label_rotation')
if label_fontsize or label_rotation:
from matplotlib.artist import setp
if labels is not None:
if not len(labels) == len(data):
msg = "Length of `labels` should equal length of `data`."
raise(ValueError, msg)
xticknames = ax.set_xticklabels(labels)
if label_fontsize:
setp(xticknames, fontsize=label_fontsize)
if label_rotation:
setp(xticknames, rotation=label_rotation)
return
示例6: blanklinemarkers
def blanklinemarkers(lineid, filled=False,
marker=None, color=None, width=None, **kw):
'''Clear markerfacecolor for the specified lines and adjust the
edge width and color according to the owner line.
lineid -- integer zero based index or a matplotlib Line2D instance.
Can be also a list of indices or Line2D objects.
filled -- when True, restore the markerfacecolor
color -- use instead of line color when specified
width -- use for markeredge width if specified, otherwise use
the line width.
kw -- optional keyword arguments for additional line properties
No return value.
'''
from matplotlib.artist import setp
linehandles = findlines(lineid)
for hi in linehandles:
mi = hi.get_marker() if marker is None else marker
ci = hi.get_color() if color is None else color
mfc = ci if filled else 'none'
mec = ci
mwi = hi.get_linewidth() if width is None else width
hi.set_marker(mi)
hi.set_markerfacecolor(mfc)
hi.set_markeredgecolor(mec)
hi.set_markeredgewidth(mwi)
if kw: setp(hi, **kw)
if linehandles:
_redraw()
return
示例7: _plot
def _plot(fig, hists, labels, N, show_ticks=False):
"""
Plot pair-wise correlation histograms
"""
if N<=1:
fig.text(0.5,0.5,"No correlation plots when only one variable",ha="center",va="center")
return
vmin, vmax = inf, -inf
for data,_,_ in hists.values():
positive = data[data>0]
if len(positive) > 0:
vmin = min(vmin,numpy.amin(positive))
vmax = max(vmax,numpy.amax(positive))
norm = colors.LogNorm(vmin=vmin, vmax=vmax, clip=False)
#norm = colors.Normalize(vmin=vmin, vmax=vmax)
mapper = image.FigureImage(fig)
mapper.set_array(numpy.zeros(0))
mapper.set_cmap(cmap=COLORMAP)
mapper.set_norm(norm)
ax = {}
Nr = Nc = N-1
for i in range(0,N-1):
for j in range(i+1,N):
sharex = ax.get((0,j), None)
sharey = ax.get((i,i+1), None)
a = fig.add_subplot(Nr,Nc,(Nr-i-1)*Nc + j,
sharex=sharex, sharey=sharey)
ax[(i,j)] = a
a.xaxis.set_major_locator(MaxNLocator(4,steps=[1,2,4,5,10]))
a.yaxis.set_major_locator(MaxNLocator(4,steps=[1,2,4,5,10]))
data,x,y = hists[(i,j)]
data = numpy.clip(data,vmin,vmax)
a.pcolorfast(y,x,data,cmap=COLORMAP,norm=norm)
# Show labels or hide ticks
if i != 0:
artist.setp(a.get_xticklabels(),visible=False)
if i == N-2 and j == N-1:
a.set_xlabel(labels[j])
#a.xaxis.set_label_position("top")
#a.xaxis.set_offset_position("top")
if not show_ticks:
a.xaxis.set_ticks([])
if j == i+1:
a.set_ylabel(labels[i])
else:
artist.setp(a.get_yticklabels(),visible=False)
if not show_ticks:
a.yaxis.set_ticks([])
a.zoomable=True
# Adjust subplots and add the colorbar
fig.subplots_adjust(left=.07, bottom=.07, top=.9, right=0.85,
wspace=0.0, hspace=0.0)
cax = fig.add_axes([0.88, 0.2, 0.04, 0.6])
fig.colorbar(mapper, cax=cax, orientation='vertical')
return ax
示例8: _show_legend
def _show_legend(ax):
"""Utility function to show legend."""
leg = ax.legend(loc=1, shadow=True, fancybox=True, labelspacing=0.2,
borderpad=0.15)
ltext = leg.get_texts()
llines = leg.get_lines()
from matplotlib.artist import setp
setp(ltext, fontsize='small')
setp(llines, linewidth=1)
示例9: animate_function
def animate_function(i):
global a
if a<time_steps:
line.set_data(X, Array[i,:])
setp(line, linewidth=2, color='r')
# line = Line2D(X, Array[:,i], color='red', linewidth=2)
else:
line.set_data(X, Array[-1,:])
a+=1
return line
示例10: changeStyle
def changeStyle(self, curveRef, style):
"""change curve style
curveRef -- internal reference to curves
style -- style dictionary
"""
stylestr, properties = self.__translateStyles(style)
#FIXME: we discard stylestr because it seems there's no way
# it can be changed afterwards.
setp((curveRef,), **properties)
self.subplot.legend(**legendBoxProperties())
示例11: test_setp
def test_setp():
# Check arbitrary iterables
fig, axes = plt.subplots()
lines1 = axes.plot(range(3))
lines2 = axes.plot(range(3))
martist.setp(chain(lines1, lines2), 'lw', 5)
plt.setp(axes.spines.values(), color='green')
# Check `file` argument
sio = io.StringIO()
plt.setp(lines1, 'zorder', file=sio)
assert sio.getvalue() == ' zorder: any number \n'
示例12: animate_function
def animate_function(i):
global a
if i == 0:
time.sleep(0.3)
if a < time_steps:
lines[1].set_data(X, Array[i, :])
setp(lines[1], linewidth=2.6, color="k")
else:
lines[1].set_data(X, Array[-1, :])
a += 1
return lines
示例13: show
def show(self, hardrefresh=True):
"""
Show graphics dependent on the current buffering state.
"""
if not hardrefresh: return
if not self.buffering:
if self.loc is not None:
for sp in self.subplots:
lines = []
labels = []
i = 0
for line in sp['lines']:
i += 1
if line is not None:
lines.append(line[0])
lbl = line[0].get_label()
if lbl == '':
lbl = str(i)
labels.append(lbl)
if len(lines):
fp = FP(size=rcParams['legend.fontsize'])
#fsz = fp.get_size_in_points() - len(lines)
fsz = fp.get_size_in_points() - max(len(lines),self.cols)
#fp.set_size(max(fsz,6))
fp.set_size(max(fsz,8))
sp['axes'].legend(tuple(lines), tuple(labels),
self.loc, prop=fp)
#else:
# sp['axes'].legend((' '))
from matplotlib.artist import setp
fpx = FP(size=rcParams['xtick.labelsize'])
xts = fpx.get_size_in_points()- (self.cols)/2
fpy = FP(size=rcParams['ytick.labelsize'])
yts = fpy.get_size_in_points() - (self.rows)/2
fpa = FP(size=rcParams['axes.labelsize'])
fpat = FP(size=rcParams['axes.titlesize'])
axsize = fpa.get_size_in_points()
tsize = fpat.get_size_in_points()-(self.cols)/2
for sp in self.subplots:
ax = sp['axes']
ax.title.set_size(tsize)
setp(ax.get_xticklabels(), fontsize=xts)
setp(ax.get_yticklabels(), fontsize=yts)
off = 0
if self.cols > 1: off = self.cols
ax.xaxis.label.set_size(axsize-off)
off = 0
if self.rows > 1: off = self.rows
ax.yaxis.label.set_size(axsize-off)
示例14: cla
def cla(self):
super().cla()
martist.setp(self.get_children(), visible=False)
self._get_lines = self._parent_axes._get_lines
# In mpl's Axes, zorders of x- and y-axis are originally set
# within Axes.draw().
if self._axisbelow:
self.xaxis.set_zorder(0.5)
self.yaxis.set_zorder(0.5)
else:
self.xaxis.set_zorder(2.5)
self.yaxis.set_zorder(2.5)
示例15: plot
def plot(self, windir, windspeed, windfrequency):
self.windir = []
self.windspeed = []
for i, frequency in enumerate(windfrequency):
for n in range(frequency):
self.windir.append(windir[i])
self.windspeed.append(windspeed[i])
self.axes.clear()
self.axes.bar(self.windir, self.windspeed, normed=True, opening=0.8, edgecolor='white')
l = self.axes.legend(borderaxespad=-3.8)
setp(l.get_texts(), fontsize=8)
# force redraw the canvas
self.fig.canvas.draw()