当前位置: 首页>>代码示例>>Python>>正文


Python BboxImage.set_array方法代码示例

本文整理汇总了Python中matplotlib.image.BboxImage.set_array方法的典型用法代码示例。如果您正苦于以下问题:Python BboxImage.set_array方法的具体用法?Python BboxImage.set_array怎么用?Python BboxImage.set_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.image.BboxImage的用法示例。


在下文中一共展示了BboxImage.set_array方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plothist

# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_array [as 别名]
def plothist(ax=      None,
             xdata= np.arange(4, 9),
             ydata= np.random.random(5),
             labels= [],
             colors = 'random',
             figName='redunca03'):
    if len(xdata) != len(ydata):
        raise StandardError('xdata and ydata must have the same len()')
    
    try:
        IMAGESPATH= os.path.join(wx.GetApp().installDir, 'nicePlot','images')
    except:
        path1= sys.argv[0]
        if os.path.isfile(path1):
            path1= os.path.split(path1)[0]
        path1= path1.decode( sys.getfilesystemencoding())
        if os.path.split( path1)[-1] == 'nicePlot':
            IMAGESPATH= os.path.join( path1, 'images')
        else:
            IMAGESPATH= os.path.join( path1, 'nicePlot', 'images')
           
    # se generan los colores en forma aleatoria
    box_colors = _generatecolors( colors,len( xdata))
    # se genera la figura
    fig = plt.gcf()
    if ax == None:
        ax = plt.gca()
    fmt = ScalarFormatter( useOffset=False)
    ax.xaxis.set_major_formatter( fmt)
    for year, h, bc in zip( xdata, ydata, box_colors):
        bbox0 = Bbox.from_extents(year-0.5, 0.0, year+0.5, h) # year-0.48, 0., year+0.48, year-1 year+1
        bbox = TransformedBbox(bbox0, ax.transData)
        rb_patch = _RibbonBoxImage(bbox, bc, figName, 
                                   path=  os.path.join(IMAGESPATH, 'histplot'),
                                   interpolation="bicubic")
        ax.add_artist(rb_patch)
        if 0:
            if type(h) == type(1):
                ax.annotate(r"%d" % h,
                        (year, h), va="bottom", ha="center")
            elif type(h) == type(1.1):
                ax.annotate(r"%f" % h,
                        (year, h), va="bottom", ha="center")
            elif str(type(h)) == "<type 'numpy.int32'>":
                ax.annotate(r"%d" % h,
                        (year, h), va="bottom", ha="center")
    patch_gradient = BboxImage( ax.bbox,
                               interpolation="bicubic",
                               zorder=0.1,
                               )
    gradient = np.zeros( (2, 2, 4), dtype=np.float)
    gradient[:,:,:3] = [1, 1, 1]
    gradient[:,:,3] = [[0.2, 0.3],[0.2, 0.5]] # alpha channel
    patch_gradient.set_array( gradient)
    ax.add_artist( patch_gradient)
    ax.set_xlim( xdata[0]-1.0, xdata[-1]+1.0)
    # se determinan los limites para el eje Y
    try:
        ydatamax = ydata.max() # en el caso de informacion proveniente de numpy
    except AttributeError:
        ydatamax = max(ydata)
    if ydatamax > 0.0:
        maxYlimit = ydatamax*1.05
    elif ydatamax == 0.0:
        maxYlimit = 1.0
    else:
        maxYlimit = ydatamax*(1.0-0.05)
    ax.set_ylim( 0, maxYlimit)
    return ( fig,plt)
开发者ID:debbiespiegel,项目名称:salstat-statistics-package-2,代码行数:71,代码来源:graficaRibon.py

示例2: ScalarFormatter

# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_array [as 别名]
    heights = np.random.random(years.shape) * 7000 + 3000

    fmt = ScalarFormatter(useOffset=False)
    ax.xaxis.set_major_formatter(fmt)

    for year, h, bc in zip(years, heights, box_colors):
        bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h)
        bbox = TransformedBbox(bbox0, ax.transData)
        rb_patch = RibbonBoxImage(bbox, bc, interpolation="bicubic")

        ax.add_artist(rb_patch)

        ax.annotate(r"%d" % (int(h/100.)*100),
                    (year, h), va="bottom", ha="center")

    patch_gradient = BboxImage(ax.bbox,
                               interpolation="bicubic",
                               zorder=0.1,
                               )
    gradient = np.zeros((2, 2, 4), dtype=np.float)
    gradient[:, :, :3] = [1, 1, 0.]
    gradient[:, :, 3] = [[0.1, 0.3], [0.3, 0.5]]  # alpha channel
    patch_gradient.set_array(gradient)
    ax.add_artist(patch_gradient)

    ax.set_xlim(years[0]-0.5, years[-1]+0.5)
    ax.set_ylim(0, 10000)

    fig.savefig('ribbon_box.png')
    plt.show()
开发者ID:astro-ming,项目名称:matplotlib,代码行数:32,代码来源:demo_ribbon_box.py

示例3: plotBar

# 需要导入模块: from matplotlib.image import BboxImage [as 别名]
# 或者: from matplotlib.image.BboxImage import set_array [as 别名]
def plotBar(ax=      None,
            xdata=   np.arange(4, 9),
            ydata=   np.random.random(5),
            labels=  None,
            colors=  'Random',
            figName= 'cilindro',
            path=    None):
    '''box_colors: 'random'|'blue'|'red'|'green'|'ligthgreen'|'darkblue'|'hsv'
    figure: redunca02|blue|aluminio|cilindro| 
    ''' 
    try:
        IMAGESPATH= os.path.join(wx.GetApp().installDir, 'nicePlot','images')
    except:
        path1= sys.argv[0]
        if os.path.isfile(path1):
            path1= os.path.split(path1)[0]
        path1= path1.decode( sys.getfilesystemencoding())
        if os.path.split( path1)[-1] == 'nicePlot':
            IMAGESPATH= os.path.join( path1, 'images')
        else:
            IMAGESPATH= os.path.join( path1, 'nicePlot', 'images')
        
    if len(xdata) != len(ydata):
        raise StandardError('xdata and ydata must have the same len()')
    
    if isinstance(figName,(str,unicode)):
        figName = [figName.lower() for i in range(len(xdata))]
    else:
        figName = [fig.lower() for fig in figName]
    ##xdata,ydata = orderData(xdata,ydata)
    # se generan los colores en forma aleatoria
    box_colors = _generatecolors(colors,len(xdata))           
    fig = plt.gcf()
    if ax == None:
        ax = plt.gca()
    fmt = ScalarFormatter(useOffset= True) #False
    ax.xaxis.set_major_formatter(fmt)
    if labels== None:
        labels = [None for i in ydata]
        
    if path == None:
        path= os.path.relpath(os.path.join(IMAGESPATH,'barplot'))

    for year, h, bc,label,figi in zip(xdata, ydata, box_colors,labels,figName):
        if h < 0: continue
        bbox0 = Bbox.from_extents(year-0.5, 0., year+0.5, h) # year-0.4, 0., year+0.4,
        bbox = TransformedBbox(bbox0, ax.transData)
        rb_patch = _RibbonBoxImage(bbox, bc, figi, path, interpolation='bicubic') #bicubic
        ax.add_artist(rb_patch)
        if isinstance(label,(str,unicode)):
            ax.annotate(label, (year, h), va="bottom", ha="center")
            if type(labels) == type(1):
                ax.annotate(r"%d" % labels,
                        (year, labels), va="bottom", ha="center")
            elif type(labels) == type(1.1):
                ax.annotate(r"%f" % labels,
                        (year, labels), va="bottom", ha="center")
            elif str(type(labels)) == "<type 'numpy.int32'>":
                ax.annotate(r"%d" % labels,
                        (year, labels), va="bottom", ha="center")
                
    patch_gradient = BboxImage(ax.bbox,
                               interpolation= 'bicubic', # "bicubic"
                               zorder=0.1,
                               )
    gradient = np.zeros((2, 2, 4), dtype=np.float)
    gradient[:,:,:3] = [1, 1, 1]
    #gradient[:,:,:3] = [0.5, 0.5, 0.5]
    gradient[:,:,3] = [[0.2, 0.3],[0.2, 0.5]] # alpha channel
    patch_gradient.set_array(gradient)
    ax.add_artist(patch_gradient)
    ax.set_xlim( min(xdata)-0.5, max(xdata)+0.5)
    # se determinan los limites para el eje Y
    if max(ydata) > 0.0:
        maxYlimit = max(ydata)*1.05
    elif max(ydata) == 0.0:
        maxYlimit = 1.0
    else:
        maxYlimit = max(ydata)*(1-0.05)
    ax.set_ylim(min(ydata)*(-0.05), maxYlimit)
    return (fig, plt)
开发者ID:debbiespiegel,项目名称:salstat-statistics-package-2,代码行数:83,代码来源:graficaRibon.py


注:本文中的matplotlib.image.BboxImage.set_array方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。