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


Python Axes.legend方法代码示例

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


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

示例1: plot_mods

# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import legend [as 别名]
def plot_mods(ax: Axes, stats: Stats, most_popular_at_bottom=False, percentage=False):
    # FIXME different colors when using percentage with 10 mods
    mods_by_popularity = sorted(stats.players_by_mod.keys(),
                                key=lambda mod: stats.all_time_players_by_mod[mod], reverse=most_popular_at_bottom)
    labels = ["{} - avg. {:.2f} players".format(mod, stats.all_time_players_by_mod[mod] / len(stats.dates))
              for mod in mods_by_popularity]

    colors = ['red', 'green', 'blue', 'yellow', 'purple', 'lime', 'gray', 'cyan', 'orange', 'deeppink', 'black']
    colors = colors[0:len(mods_by_popularity)]
    colors = colors if most_popular_at_bottom else reversed(colors)
    ax.set_prop_cycle(color=colors)

    all_mods_values = np.row_stack([stats.players_by_mod[mod] for mod in mods_by_popularity])
    if percentage:
        with np.errstate(invalid='ignore'):
            all_mods_values = all_mods_values / all_mods_values.sum(axis=0) * 100
    ax.stackplot(stats.dates, all_mods_values, labels=labels, linewidth=0.1)

    if percentage:
        ax.set_ylim(bottom=0, top=100)
    else:
        ax.set_ylim(bottom=0)
    decorate_axes(ax)
    handles, labels = ax.get_legend_handles_labels()
    handles = handles if most_popular_at_bottom else reversed(handles)
    labels = labels if most_popular_at_bottom else reversed(labels)
    leg = ax.legend(handles, labels, loc='upper left', prop={'size': 10})
    leg.get_frame().set_alpha(0.5)
开发者ID:martin-t,项目名称:xon-activity-stats,代码行数:30,代码来源:qstat-parser.py

示例2: plot_servers

# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import legend [as 别名]
def plot_servers(ax: Axes, stats: Stats):
    ax.plot_date(stats.dates, stats.active_servers, 'g')
    # ax.plot_date(stats.dates, stats.players_on_most_active_server, 'black')
    ax.plot_date(stats.dates, stats.avg_players_per_active_server, 'gray')

    ax.set_ylim(bottom=0)
    decorate_axes(ax)
    highlight_weekends(stats.dates, ax)
    leg = ax.legend(["Active servers", "Average humans per active server"], loc='upper left')
    leg.get_frame().set_alpha(0.5)
开发者ID:martin-t,项目名称:xon-activity-stats,代码行数:12,代码来源:qstat-parser.py

示例3: drawEP

# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import legend [as 别名]
def drawEP(fig, n, roundN, endowments, prices):
    ax = Axes(fig, [.1, .55, .8, .35])
    ax.grid(True)
    ax.set_xticks( range(roundN+1) )
    ax.set_frame_on(False)

    users = [[] for i in range(n)]
    for i in range(n):
        for j in range(roundN):
            users[i].append( float(Fraction(endowments[j][i])) )
        users[i].append( float(Fraction(prices[roundN-1][i])) )

    x = range(roundN+1)
    for i in range(n):
        price = round(float(Fraction(prices[roundN-1][i])), 3)
        ax.plot(x, users[i], linestyle = '--', marker = 'o', label = str(i) + ": " + str(price))
#    ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=2, ncol=min(n, 5), mode="expand", borderaxespad=0.)
    ax.legend()

    fig.add_axes( ax )
开发者ID:iSuneast,项目名称:Market,代码行数:22,代码来源:makeLog.py

示例4: legend

# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import legend [as 别名]
def legend(plot, colors, labels, shape='rectangle', loc='upper left', **kwargs):
    """
    RR: the MPL legend function has changed since this function has been
    written. This function currently does not work. -CZ
    """
    if shape == 'circle':
        shapes = [ Circle((0.5,0.5), radius=1, fc=c) for c in colors ]
        #shapes = [ CircleCollection([10],facecolors=[c]) for c in colors ]
    else:
        shapes = [ Rectangle((0,0),1,1,fc=c,ec='none') for c in colors ]

    return Axes.legend(plot, shapes, labels, loc=loc, **kwargs)
开发者ID:rhr,项目名称:ivy,代码行数:14,代码来源:symbols.py

示例5: plot_totals

# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import legend [as 别名]
def plot_totals(ax: Axes, stats: Stats):
    ax.plot_date(stats.dates, stats.total_servers, 'g')
    ax.plot_date(stats.dates, stats.total_human_players, 'black')
    ax.plot_date(stats.dates, stats.total_active_players, 'r')
    ax.plot_date(stats.dates, stats.total_spectators, 'orange')
    ax.plot_date(stats.dates, stats.total_bots, 'lime')

    ax.set_ylim(bottom=0)
    decorate_axes(ax)
    highlight_weekends(stats.dates, ax)
    leg = ax.legend(["Servers", "Human players", "Playing", "Spectating", "Bots"], loc='upper left')
    leg.get_frame().set_alpha(0.5)
开发者ID:martin-t,项目名称:xon-activity-stats,代码行数:14,代码来源:qstat-parser.py

示例6: legend

# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import legend [as 别名]
    def legend(self, *args, **kwargs):
        this_axes = self
        class SmithHandlerLine2D(HandlerLine2D):
            def create_artists(self, legend, orig_handle,
                xdescent, ydescent, width, height, fontsize,
                trans):
                legline, legline_marker = HandlerLine2D.create_artists(self, legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)

                if hasattr(orig_handle, "_markerhacked"):
                    this_axes._hack_linedraw(legline_marker, True)
                return [legline, legline_marker]
        return Axes.legend(self, *args, handler_map={Line2D : SmithHandlerLine2D()}, **kwargs)
开发者ID:openchip,项目名称:red-pitaya-notes,代码行数:14,代码来源:smithaxes.py

示例7: legend

# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import legend [as 别名]
    def legend(self, *args, **kwargs):
        """call signature::

          legend(*args, **kwargs)

        Place a legend on the current axes at location *loc*.  Labels are a
        sequence of strings and *loc* can be a string or an integer specifying
        the legend location.

        To make a legend with existing lines::

          legend()

        :meth:`legend` by itself will try and build a legend using the label
        property of the lines/patches/collections.  You can set the label of
        a line by doing::

          plot(x, y, label='my data')

        or::

          line.set_label('my data').

        If label is set to '_nolegend_', the item will not be shown in
        legend.

        To automatically generate the legend from labels::

          legend( ('label1', 'label2', 'label3') )

        To make a legend for a list of lines and labels::

          legend( (line1, line2, line3), ('label1', 'label2', 'label3') )

        To make a legend at a given location, using a location argument::

          legend( ('label1', 'label2', 'label3'), loc='upper left')

        or::

          legend( (line1, line2, line3),  ('label1', 'label2', 'label3'), loc=2)

        The location codes are

          ===============   =============
          Location String   Location Code
          ===============   =============
          'best'            0
          'upper right'     1
          'upper left'      2
          'lower left'      3
          'lower right'     4
          'right'           5
          'center left'     6
          'center right'    7
          'lower center'    8
          'upper center'    9
          'center'          10
          ===============   =============


        Users can specify any arbitrary location for the legend using the
        *bbox_to_anchor* keyword argument. bbox_to_anchor can be an instance
        of BboxBase(or its derivatives) or a tuple of 2 or 4 floats.
        For example,

          loc = 'upper right', bbox_to_anchor = (0.5, 0.5)

        will place the legend so that the upper right corner of the legend at
        the center of the axes.

        The legend location can be specified in other coordinate, by using the
        *bbox_transform* keyword.

        The loc itslef can be a 2-tuple giving x,y of the lower-left corner of
        the legend in axes coords (*bbox_to_anchor* is ignored).


        Keyword arguments:

          *prop*: [ None | FontProperties | dict ]
            A :class:`matplotlib.font_manager.FontProperties`
            instance. If *prop* is a dictionary, a new instance will be
            created with *prop*. If *None*, use rc settings.

          *numpoints*: integer
            The number of points in the legend for line

          *scatterpoints*: integer
            The number of points in the legend for scatter plot

          *scatteroffsets*: list of floats
            a list of yoffsets for scatter symbols in legend

          *markerscale*: [ None | scalar ]
            The relative size of legend markers vs. original. If *None*, use rc
            settings.

          *frameon*: [ True | False ]
            if True, draw a frame around the legend.
#.........这里部分代码省略.........
开发者ID:kdavies4,项目名称:matplotlib,代码行数:103,代码来源:ternary.py


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