本文整理汇总了Python中matplotlib.patches.Rectangle.set_alpha方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.set_alpha方法的具体用法?Python Rectangle.set_alpha怎么用?Python Rectangle.set_alpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.set_alpha方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __plot_volume
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def __plot_volume(self, ax, params=None):
if params is None:
width = 0.6
else:
width = params["width"]
prices = self.prices.tail(self.candlestick_num)
for i in self.indices:
p = prices.iloc[i, :]
open = p["Open"]
close = p["Close"]
volume = p["Volume"]
if close >= open:
color = "red"
else:
color = "green"
rect = Rectangle(
xy = (i - width/2, 0),
width = width,
height = volume,
facecolor = color,
edgecolor = color,
)
rect.set_alpha(0.5)
ax.add_patch(rect)
ax.set_ylim([0, prices["Volume"].max() * 1.25])
ax.grid(b=True, axis='x')
示例2: candlestick
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def candlestick(ax, quotes, width=0.2, colorup="k", colordown="r", alpha=1.0):
OFFSET = width / 2.0
lines = []
patches = []
for q in quotes:
t, open, close, high, low = q[:5]
if close >= open:
color = colorup
lower = open
height = close - open
else:
color = colordown
lower = close
height = open - close
vline = Line2D(xdata=(t, t), ydata=(low, high), color=color, linewidth=0.5, antialiased=True)
rect = Rectangle(xy=(t - OFFSET, lower), width=width, height=height, facecolor=color, edgecolor=color)
rect.set_alpha(alpha)
lines.append(vline)
patches.append(rect)
ax.add_line(vline)
ax.add_patch(rect)
ax.autoscale_view()
return lines, patches
示例3: candlestick
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def candlestick(self, axis, prices, width=0.5, colorup='green',
colordown='red', alpha=1.0):
"""
Plot the time, open, close, high, low as a vertical line ranging
from low to high. Use a rectangular bar to represent the
open-close span. If close >= open, use colorup to color the bar,
otherwise use colordown
ax : an Axes instance to plot to
width : fraction of a day for the rectangle width
colorup : the color of the rectangle where close >= open
colordown : the color of the rectangle where close < open
alpha : the rectangle alpha level
"""
dates = []
lines = []
for date in self.dates:
t = date2num(date)
close = prices.close[date]
open_ = prices.open[date]
if close >= open_:
color = colorup
lower = open_
height = close - open_
else:
color = colordown
lower = close
height = open_ - close
lines.extend([prices.low[date], prices.high[date], None])
dates.extend([t, t, None])
rect = Rectangle(xy=(t - width/2, lower), width=width,
height=height, facecolor=color, edgecolor=color, zorder=2)
rect.set_alpha(alpha)
axis.add_patch(rect)
axis.plot(dates, lines, linewidth=0.5, zorder=1, antialiased=True)
return min(y for y in lines if y is not None), max(lines)
示例4: plotKLine
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def plotKLine(self, data, timescale=1.0,
width=0.9, colorup='r', colorflat = 'w', colordown='g', alpha=1.0):
self.priceChart.set_xlim(data[0]-50*timescale/86400,data[0]+8*timescale/86400)
t, open, close, high, low = data[:5]
if close > open:
color = colorup
elif close == open:
color = colorflat
else:
color = colordown
if close == open:
close = open + 0.005
shadowline = Line2D(xdata=(t, t), ydata=(low, high),
color=color,linewidth=0.5,antialiased=True,)
rect = Rectangle(xy = (t-width*timescale/172800, open),
width = width*timescale/86400,
height = close-open, facecolor=color, edgecolor=color,)
rect.set_alpha(alpha)
#self.priceChart.axhline(y=close,xmin=0.2,xmax=0.8)
self.priceChart.add_line(shadowline)
self.priceChart.add_patch(rect)
#返回画的图形,方便后面adjust
return shadowline, rect
示例5: __plot_candlestick
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def __plot_candlestick(self, ax, width=0.5, colorup='red', colordown='green', alpha=0.8):
offset = width / 2.0
line_width = width * 2
prices = self.prices.tail(self.candlestick_num)
for i in self.indices:
p = prices.iloc[i, :]
open = p["Open"]
close = p["Close"]
high = p["High"]
low = p["Low"]
box_high = max(open, close)
box_low = min(open, close)
height = box_high - box_low
if close >= open:
color = colorup
else:
color = colordown
vline_low = Line2D(
xdata=(i, i), ydata=(low, box_low),
color = 'black',
linewidth=line_width,
antialiased=True,
)
vline_high = Line2D(
xdata=(i, i), ydata=(box_high, high),
color = 'black',
linewidth=line_width,
antialiased=True,
)
rect = Rectangle(
xy = (i - offset, box_low),
width = width,
height = height,
facecolor = color,
edgecolor = color,
)
rect.set_alpha(alpha)
ax.add_line(vline_low)
ax.add_line(vline_high)
ax.add_patch(rect)
ax.autoscale_view()
示例6: addTicker
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def addTicker(self, ticker):
t = date2num(ticker.getDate())
open = ticker.getOpen()
close = ticker.getAdjustedClose()
high = ticker.getHigh()
low = ticker.getLow()
volume = ticker.getVolume()
if close >= open:
color = self.__colorup
lower = open
height = close - open
else:
color = self.__colordown
lower = close
height = open - close
vline = Line2D(
xdata=(t, t), ydata=(low, high),
color='k',
linewidth=1,
antialiased=True,
)
rectTicker = Rectangle(
xy=(t - self.__offset, lower),
width = self.__candleWidth,
height = height,
facecolor = color,
edgecolor = color,
)
rectTicker.set_alpha(self.__alpha)
rectVolume = Rectangle(
xy=(t - self.__offset, 0),
width = self.__candleWidth,
height = volume,
facecolor = color,
edgecolor = color,
)
self.__axCandle.add_line(vline)
self.__axCandle.add_patch(rectTicker)
self.__axVolume.add_patch(rectVolume)
示例7: boundingBox
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def boundingBox(self, data, ax, label, bBoundingBoxes, bLabels):
''' Draw bounding box around data.'''
data = np.array(data)
width = max(data[:,0]) - min(data[:,0])
height = max(data[:,1]) - min(data[:,1])
r = Rectangle((min(data[:,0]), min(data[:,1])), width, height)
if bBoundingBoxes:
ax.add_artist(r)
r.set_clip_box(ax.bbox)
r.set_alpha(0.1)
r.set_facecolor((0.5, 0.5, 0.5))
if bLabels:
ax.annotate(label, xy = (min(data[:,0]), max(data[:,1])), xytext = (0, 0),
textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.5', fc = (0.5, 0.5, 0.5), alpha = 0.1))
示例8: candlestick
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def candlestick(ax, quotes_df, width=0.2, colorup='w', colordown='k', alpha=1.0):
lines = []
patches = []
offset = width/2.0
for i in range(len(quotes_df)):
pr_open = quotes_df['Open'][i]
pr_high = quotes_df['High'][i]
pr_low = quotes_df['Low'][i]
pr_close = quotes_df['Close'][i]
if pr_close >= pr_open:
color = colorup
lower = pr_open
upper = pr_close
height = pr_close - pr_open
else:
color = colordown
lower = pr_close
upper = pr_open
height = pr_open - pr_close
vline = Line2D(xdata=(i, i), ydata=(pr_low, lower), color='k', linewidth=0.5, antialiased=True)
vline2 = Line2D(xdata=(i, i), ydata=(upper, pr_high), color='k', linewidth=0.5, antialiased=True)
rect = Rectangle(xy=(i - offset, lower), width=width, height=height, facecolor=color,
edgecolor='k', linewidth=0.5)
rect.set_alpha(alpha)
lines.append(vline)
lines.append(vline2)
patches.append(rect)
ax.add_line(vline)
ax.add_line(vline2)
ax.add_patch(rect)
ax.set_xlim(0, len(quotes_df))
ax.grid(axis='x', color='0.4', aa=True)
ax.autoscale_view()
return lines, patches
示例9: plotVolume
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def plotVolume(self, data, timescale=1.0,
width=0.9, colorup='r', colorflat='w',colordown='g', alpha=1.0):
u"""根据数据画一个新的成交量rect"""
self.volumeChart.set_xlim(data[0]-50*timescale/86400,data[0]+8*timescale/86400)
t, open, close= data[:3]
volume = data[5]
if close > open:
color = colorup
elif close == open:
color = colorflat
else:
color = colordown
rect = Rectangle(xy = (t-width*timescale/172800, 0),
width = width*timescale/86400,
height = volume, facecolor=color, edgecolor=color)
rect.set_alpha(alpha)
self.volumeChart.add_patch(rect)
return rect
示例10: candlestick
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def candlestick(self, X = [],Y = [], # X-Y points in the graph.
labels = [], legend = [], # Basic Labelling
color = None, lw = 2, alpha = 1.0, # Basic line properties
nf = 0, na = 0, # New axis. To plot in a new axis # TODO: shareX option
ax = None, position = [], projection = "2d", # Type of plot
sharex = None, sharey = None,
fontsize = 20,fontsizeL = 10, fontsizeA = 15, # The font for the labels in the axis
xlim = None, ylim = None, xlimPad = None, ylimPad = None, # Limits of vision
ws = None, Ninit = 0,
loc = "best",
dataTransform = None,
xaxis_mode = None,yaxis_mode = None,AxesStyle = None, # Automatically do some formatting :)
barwidth = None, colorup = "g", colordown = "r"
):
# Management of the figure and properties
ax = self.figure_management(nf, na, ax = ax, sharex = sharex, sharey = sharey,
projection = projection, position = position)
## Preprocess the data given so that it meets the right format
X, Y = self.preprocess_data(X,Y,dataTransform)
NpY, NcY = Y.shape
plots,plots_typ = self.init_WidgetData(ws)
##################### PREPROCESSING AND PLOTTING #######################
# Prepare the data
openp = Y[self.start_indx:self.end_indx,0]
closep = Y[self.start_indx:self.end_indx,1]
highp = Y[self.start_indx:self.end_indx,2]
lowp = Y[self.start_indx:self.end_indx,3]
dates = X[self.start_indx:self.end_indx]
dates = ul.preprocess_dates(dates)
if (type(barwidth) == type(None)):
barwidth = self.get_barwidth(dates, barwidth) * 0.8
# PLOTTING !!
Npoints = dates.size
OFFSET = barwidth / 2.0
line_factor = 0.15
barwidth_HL = barwidth * line_factor
OFFSET_HL = barwidth_HL / 2.0
lines = []
patches = []
for i in range(Npoints):
if closep[i] >= openp[i] :
color = colorup
baseRectable = openp[i]
else:
color = colordown
baseRectable = closep[i]
height = np.abs(openp[i] - closep[i])
## High-low line
# line_HL = Line2D(
# xdata=(dates[i],dates[i]), ydata=(lowp[i], highp[i]),
# color=color,
# linewidth=lw,
# antialiased=True,
# )
rect_HL = Rectangle(
xy=(dates[i] - OFFSET_HL, lowp[i]),
width=barwidth_HL,
height=highp[i] - lowp[i],
facecolor=color,
edgecolor=color,
)
# print type(dates[i]), type(OFFSET)
## Open Close rectangle
rect_OP = Rectangle(
xy=(dates[i] - OFFSET, baseRectable),
width=barwidth,
height=height,
facecolor=color,
edgecolor=color,
)
rect_OP.set_alpha(alpha)
#
# lines.append(line_HL)
# patches.append(rect_OP)
# ax.add_line(line_HL)
ax.add_patch(rect_OP)
ax.add_patch(rect_HL)
# lines = mc.LineCollection(lines)
# ax.add_collection(lines)
# ax.add_collection(patches)
ax.autoscale() # TODO: The zoom is not changed if we do not say it !
############### Last setting functions ###########################
self.store_WidgetData(plots_typ, plots) # Store pointers to variables for interaction
#.........这里部分代码省略.........
示例11: candlestick
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
alpha=1.0):
"""
quotes is a sequence of (time, open, close, high, low, ...) sequences.
As long as the first 5 elements are these values,
the record can be as long as you want (eg it may store volume).
time must be in float days format - see date2num
Plot the time, open, close, high, low as a vertical line ranging
from low to high. Use a rectangular bar to represent the
open-close span. If close >= open, use colorup to color the bar,
otherwise use colordown
ax : an Axes instance to plot to
width : fraction of a day for the rectangle width
colorup : the color of the rectangle where close >= open
colordown : the color of the rectangle where close < open
alpha : the rectangle alpha level
return value is lines, patches where lines is a list of lines
added and patches is a list of the rectangle patches added
"""
OFFSET = width/2.0
lines = []
patches = []
for q in quotes:
t, open, close, high, low = q[:5]
if close>=open :
color = colorup
lower = open
height = close-open
else :
color = colordown
lower = close
height = open-close
vline = Line2D(
xdata=(t, t), ydata=(low, high),
color='k',
linewidth=0.5,
antialiased=True,
)
rect = Rectangle(
xy = (t-OFFSET, lower),
width = width,
height = height,
facecolor = color,
edgecolor = color,
)
rect.set_alpha(alpha)
lines.append(vline)
patches.append(rect)
ax.add_line(vline)
ax.add_patch(rect)
ax.autoscale_view()
return lines, patches
示例12: _candlestick
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def _candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
alpha=1.0, ochl=True):
"""
Plot the time, open, high, low, close as a vertical line ranging
from low to high. Use a rectangular bar to represent the
open-close span. If close >= open, use colorup to color the bar,
otherwise use colordown
Parameters
----------
ax : `Axes`
an Axes instance to plot to
quotes : sequence of quote sequences
data to plot. time must be in float date format - see date2num
(time, open, high, low, close, ...) vs
(time, open, close, high, low, ...)
set by `ochl`
width : float
fraction of a day for the rectangle width
colorup : color
the color of the rectangle where close >= open
colordown : color
the color of the rectangle where close < open
alpha : float
the rectangle alpha level
ochl: bool
argument to select between ochl and ohlc ordering of quotes
Returns
-------
ret : tuple
returns (lines, patches) where lines is a list of lines
added and patches is a list of the rectangle patches added
"""
OFFSET = width / 2.0
lines = []
patches = []
for q in quotes:
if ochl:
t, open, close, high, low = q[:5]
else:
t, open, high, low, close = q[:5]
if close >= open:
color = colorup
lower = open
height = close - open
else:
color = colordown
lower = close
height = open - close
vline = Line2D(
xdata=(t, t), ydata=(low, high),
color=color,
linewidth=0.5,
antialiased=True,
)
rect = Rectangle(
xy=(t - OFFSET, lower),
width=width,
height=height,
facecolor=color,
edgecolor=color,
)
rect.set_alpha(alpha)
lines.append(vline)
patches.append(rect)
ax.add_line(vline)
ax.add_patch(rect)
ax.autoscale_view()
return lines, patches
示例13: getRectangle
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def getRectangle(x, y, width, height, color, alpha=1):
rect = Rectangle((x, y), width, height)
rect.set_color(color)
rect.set_alpha(alpha)
return rect
示例14: candlestick
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def candlestick(ax, data, width=0.6, colorup='r', colordown='g', time_format="%Y-%m-%d", alpha=0.7):
""" Optimized candle stick graph interface.
:type ax matplotlib.axes.Axes
"""
offset = width / 2.0
timeseries = data.index
t = [tt.strftime(time_format) for tt in timeseries]
oo = data['open']
cc = data['close']
hh = data['high']
ll = data['low']
ax.set_xlim(0.0, len(t)*width)
major_locator = MultipleLocator(20*width)
minor_locator = MultipleLocator(5*width)
ax.set_xticks([x*width for x in range(len(t))], minor=True)
ticklabels = [t[d] for d in range(len(timeseries)) if d % 20 == 0]
ticklabels.insert(0, 'dummy') # fix matplotlib tick bug
ax.tick_params(axis='both', direction='out', width=2, length=8,
labelsize=10, pad=8)
ax.xaxis.set_ticklabels(ticklabels, horizontalalignment='center')
ax.xaxis.set_major_locator(major_locator)
ax.xaxis.set_minor_locator(minor_locator)
lines = []
patches = []
for q in range(len(t)):
c = float(cc[q])
o = float(oo[q])
h = float(hh[q])
l = float(ll[q])
if c >= o:
color = colorup
lower = o
height = c - o
else:
color = colordown
lower = c
height = o - c
vline = Line2D(
xdata=(q*width, q*width), ydata=(l, h),
color=color,
linewidth=0.5,
antialiased=True,
)
rect = Rectangle(
xy=(q*width-offset, lower),
width = width,
height = height,
facecolor = color,
edgecolor = color,
)
rect.set_alpha(alpha)
lines.append(vline)
patches.append(rect)
ax.add_line(vline)
ax.add_patch(rect)
ax.autoscale_view()
return lines, patches
示例15: buildExcVol
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_alpha [as 别名]
def buildExcVol(cutX,cutY,cutZ,ax):
"""
Builds rectangular prism (excluded volume).
"""
r1 = Rectangle((-cutX,-cutZ),2.0*cutX,2.0*cutZ)
r4 = Rectangle((-cutX,-cutZ),2.0*cutX,2.0*cutZ)
r2 = Rectangle((-cutY,-cutZ),2.0*cutY,2.0*cutZ)
r5 = Rectangle((-cutY,-cutZ),2.0*cutY,2.0*cutZ)
r3 = Rectangle((-cutX,-cutY),2.0*cutX,2.0*cutY)
r6 = Rectangle((-cutX,-cutY),2.0*cutX,2.0*cutY)
r1.set_alpha(0.1)
r2.set_alpha(0.1)
r3.set_alpha(0.1)
r4.set_alpha(0.1)
r5.set_alpha(0.1)
r6.set_alpha(0.1)
ax.add_patch(r1), ax.add_patch(r2)
ax.add_patch(r3), ax.add_patch(r4)
ax.add_patch(r5), ax.add_patch(r6)
art3d.pathpatch_2d_to_3d(r1, z=-cutY, zdir="y")
art3d.pathpatch_2d_to_3d(r4, z=cutY, zdir="y")
art3d.pathpatch_2d_to_3d(r2, z=cutX, zdir="x")
art3d.pathpatch_2d_to_3d(r5, z=-cutX, zdir="x")
art3d.pathpatch_2d_to_3d(r3, z=cutZ, zdir="z")
art3d.pathpatch_2d_to_3d(r6, z=-cutZ, zdir="z")