當前位置: 首頁>>代碼示例>>Python>>正文


Python pyplot.xkcd方法代碼示例

本文整理匯總了Python中matplotlib.pyplot.xkcd方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.xkcd方法的具體用法?Python pyplot.xkcd怎麽用?Python pyplot.xkcd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在matplotlib.pyplot的用法示例。


在下文中一共展示了pyplot.xkcd方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_text_box

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def make_text_box(title, filename, bullet_points, width, height):
    "Create a text box with information,..."
    with plt.xkcd():
        fig, ax = plt.subplots(figsize=(width, height))
        ax.set_axis_off()
        ax.text(
            -0.15, 0.9,
            title,
            fontsize=48,
            horizontalalignment='left',
            verticalalignment='center'
        )
        for i, bp in enumerate(bullet_points):
            hh = 0.9 / len(bullet_points)
            ax.text(
                -0.1, 0.9 - ((i + 1) * hh),
                f'* {bp}',
                color='dimgrey',
                fontsize=30,
                horizontalalignment='left',
                verticalalignment='center'
            )
        fig.savefig(filename, dpi=DPI)
        return fig 
開發者ID:kikocorreoso,項目名稱:scikit-extremes,代碼行數:26,代碼來源:poster_PyConES2019_ESversion.py

示例2: make_text_box

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def make_text_box(title, filename, bullet_points, width, height):
    "Create a text box with information,..."
    with plt.xkcd():
        fig, ax = plt.subplots(figsize=(width, height))
        ax.set_axis_off()
        ax.text(
            -0.15, 0.9,
            title,
            fontsize=48,
            horizontalalignment='left',
            verticalalignment='center'
        )
        for i, bp in enumerate(bullet_points):
            hh = 0.9 / len(bullet_points)
            ax.text(
                -0.1, 0.9 - ((i + 1) * hh),
                f'* {bp}',
                color='dimgrey',
                fontsize=32,
                horizontalalignment='left',
                verticalalignment='center'
            )
        fig.savefig(filename, dpi=DPI)
        return fig 
開發者ID:kikocorreoso,項目名稱:scikit-extremes,代碼行數:26,代碼來源:poster_PyConES2019_ENversion.py

示例3: _init_plt

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def _init_plt(self):
        font = {'family': ['xkcd', 'Humor Sans', 'Comic Sans MS'],
                'weight': 'bold',
                'size': 14}
        matplotlib.rc('font', **font)
        # 這行代碼使用「手繪風格圖片」,有興趣小夥伴可以google搜索「xkcd」,有好玩的。
        plt.xkcd()
        self.bar_color = ('#55A868', '#4C72B0', '#C44E52', '#8172B2', '#CCB974', '#64B5CD')
        self.title_font_size = 'x-large' 
開發者ID:newbietian,項目名稱:WxConn,代碼行數:11,代碼來源:main.py

示例4: generate_city_pic

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def generate_city_pic(self, city_data):
        """
        生成城市數據圖片
        因為plt在子線程中執行會出現自動彈出彈框並阻塞主線程的行為,plt行為均放在主線程中
        :param data:
        :return:
        """
        font = {'family': ['xkcd', 'Humor Sans', 'Comic Sans MS'],
                'weight': 'bold',
                'size': 12}
        matplotlib.rc('font', **font)
        cities = city_data['cities']
        city_people = city_data['city_people']

        # 繪製「性別分布」柱狀圖
        plt.barh(range(len(cities)), width=city_people, align='center', color=self.bar_color, alpha=0.8)
        # 添加軸標簽
        plt.xlabel(u'Number of People')
        # 添加標題
        plt.title(u'Top %d Cities of your friends distributed' % len(cities), fontsize=self.title_font_size)
        # 添加刻度標簽
        plt.yticks(range(len(cities)), cities)
        # 設置X軸的刻度範圍
        plt.xlim([0, city_people[0] * 1.1])

        # 為每個條形圖添加數值標簽
        for x, y in enumerate(city_people):
            plt.text(y + len(str(y)), x, y, ha='center')

        # 顯示圖形
        plt.savefig(ALS.result_path + '/4.png')
        # todo 如果調用此處的關閉,就會導致應用本身也被關閉
        # plt.close()
        # plt.show() 
開發者ID:newbietian,項目名稱:WxConn,代碼行數:36,代碼來源:main.py

示例5: test_xkcd_no_cm

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def test_xkcd_no_cm():
    assert mpl.rcParams["path.sketch"] is None
    plt.xkcd()
    assert mpl.rcParams["path.sketch"] == (1, 100, 2)
    gc.collect()
    assert mpl.rcParams["path.sketch"] == (1, 100, 2) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:8,代碼來源:test_style.py

示例6: test_xkcd_cm

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def test_xkcd_cm():
    assert mpl.rcParams["path.sketch"] is None
    with plt.xkcd():
        assert mpl.rcParams["path.sketch"] == (1, 100, 2)
    assert mpl.rcParams["path.sketch"] is None 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:7,代碼來源:test_style.py

示例7: test_xkcd

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def test_xkcd():
    np.random.seed(0)

    x = np.linspace(0, 2 * np.pi, 100)
    y = np.sin(x)

    with plt.xkcd():
        fig, ax = plt.subplots()
        ax.plot(x, y) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:11,代碼來源:test_path.py

示例8: test_xkcd_marker

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def test_xkcd_marker():
    np.random.seed(0)

    x = np.linspace(0, 5, 8)
    y1 = x
    y2 = 5 - x
    y3 = 2.5 * np.ones(8)

    with plt.xkcd():
        fig, ax = plt.subplots()
        ax.plot(x, y1, '+', ms=10)
        ax.plot(x, y2, 'o', ms=10)
        ax.plot(x, y3, '^', ms=10) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:15,代碼來源:test_path.py

示例9: reset_plt

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def reset_plt(self):
        """ Reset the current matplotlib plot style. """
        import matplotlib.pyplot as plt
        plt.gcf().subplots_adjust(bottom=0.15)
        if Settings()["report/xkcd_like_plots"]:
            import seaborn as sns
            sns.reset_defaults()
            mpl.use("agg")
            plt.xkcd()
        else:
            import seaborn as sns
            sns.reset_defaults()
            sns.set_style("darkgrid")
            sns.set_palette(sns.color_palette("muted"))
            mpl.use("agg") 
開發者ID:parttimenerd,項目名稱:temci,代碼行數:17,代碼來源:stats.py

示例10: add_style_opt_to_parser

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def add_style_opt_to_parser(parser, default=None):
    """Adds an option to set the matplotlib style to a parser.

    Parameters
    ----------
    parser : argparse.ArgumentParser
        The parser to add the option to.
    default : str, optional
        The default style to use. Default, None, will result in the default
        matplotlib style to be used.
    """
    from matplotlib import pyplot
    parser.add_argument('--mpl-style', default=default,
                        choices=['default']+pyplot.style.available+['xkcd'],
                        help='Set the matplotlib style to use.') 
開發者ID:gwastro,項目名稱:pycbc,代碼行數:17,代碼來源:plot.py

示例11: set_style_from_cli

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def set_style_from_cli(opts):
    """Uses the mpl-style option to set the style for plots.

    Note: This will change the global rcParams.
    """
    from matplotlib import pyplot
    if opts.mpl_style == 'xkcd':
        # this is treated differently for some reason
        pyplot.xkcd()
    elif opts.mpl_style is not None:
        pyplot.style.use(opts.mpl_style) 
開發者ID:gwastro,項目名稱:pycbc,代碼行數:13,代碼來源:plot.py

示例12: create_code_example

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def create_code_example(title, filename, explanation, code, width, height):
    with plt.xkcd():
        fig, ax = plt.subplots(figsize=(width, height))
        ax.set_axis_off()
        ax.text(
            -0.1, 0.95,
            title,
            fontsize=40,
            horizontalalignment='left',
            verticalalignment='center'
        )
        ax.text(
            -0.05, 0.82,
            explanation,
            fontsize=30,
            horizontalalignment='left',
            verticalalignment='center'
        )
    for i, c in enumerate(code.split('\n')):
        hh = 0.75 / len(code.split('\n'))
        ax.text(
            0, 0.75 - ((i + 1) * hh),
            c,
            fontsize=15,
            horizontalalignment='left',
            verticalalignment='center'
        )
    fig.savefig(filename, transparent=True, dpi=DPI)
    return fig 
開發者ID:kikocorreoso,項目名稱:scikit-extremes,代碼行數:31,代碼來源:poster_PyConES2019_ESversion.py

示例13: xkcd

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def xkcd(scale=1, length=100, randomness=2):
    """
    Turns on `xkcd <http://xkcd.com/>`_ sketch-style drawing mode.
    This will only have effect on things drawn after this function is
    called.

    For best results, the "Humor Sans" font should be installed: it is
    not included with matplotlib.

    Parameters
    ----------
    scale: float, optional
        The amplitude of the wiggle perpendicular to the source line.
    length: float, optional
        The length of the wiggle along the line.
    randomness: float, optional
        The scale factor by which the length is shrunken or expanded.

    This function works by a number of rcParams, so it will probably
    override others you have set before.

    If you want the effects of this function to be temporary, it can
    be used as a context manager, for example::

        with plt.xkcd():
            # This figure will be in XKCD-style
            fig1 = plt.figure()
            # ...

        # This figure will be in regular style
        fig2 = plt.figure()
    """
    if rcParams['text.usetex']:
        raise RuntimeError(
            "xkcd mode is not compatible with text.usetex = True")

    from matplotlib import patheffects
    context = rc_context()
    try:
        rcParams['font.family'] = ['Humor Sans', 'Comic Sans MS']
        rcParams['font.size'] = 14.0
        rcParams['path.sketch'] = (scale, length, randomness)
        rcParams['path.effects'] = [
            patheffects.withStroke(linewidth=4, foreground="w")]
        rcParams['axes.linewidth'] = 1.5
        rcParams['lines.linewidth'] = 2.0
        rcParams['figure.facecolor'] = 'white'
        rcParams['grid.linewidth'] = 0.0
        rcParams['axes.unicode_minus'] = False
        rcParams['axes.color_cycle'] = ['b', 'r', 'c', 'm']
        rcParams['xtick.major.size'] = 8
        rcParams['xtick.major.width'] = 3
        rcParams['ytick.major.size'] = 8
        rcParams['ytick.major.width'] = 3
    except:
        context.__exit__(*sys.exc_info())
        raise
    return context


## Figures ## 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:63,代碼來源:pyplot.py

示例14: xkcd

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def xkcd(scale=1, length=100, randomness=2):
    """
    Turn on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
    This will only have effect on things drawn after this function is
    called.

    For best results, the "Humor Sans" font should be installed: it is
    not included with matplotlib.

    Parameters
    ----------
    scale : float, optional
        The amplitude of the wiggle perpendicular to the source line.
    length : float, optional
        The length of the wiggle along the line.
    randomness : float, optional
        The scale factor by which the length is shrunken or expanded.

    Notes
    -----
    This function works by a number of rcParams, so it will probably
    override others you have set before.

    If you want the effects of this function to be temporary, it can
    be used as a context manager, for example::

        with plt.xkcd():
            # This figure will be in XKCD-style
            fig1 = plt.figure()
            # ...

        # This figure will be in regular style
        fig2 = plt.figure()
    """
    if rcParams['text.usetex']:
        raise RuntimeError(
            "xkcd mode is not compatible with text.usetex = True")

    from matplotlib import patheffects
    return rc_context({
        'font.family': ['xkcd', 'Humor Sans', 'Comic Sans MS'],
        'font.size': 14.0,
        'path.sketch': (scale, length, randomness),
        'path.effects': [patheffects.withStroke(linewidth=4, foreground="w")],
        'axes.linewidth': 1.5,
        'lines.linewidth': 2.0,
        'figure.facecolor': 'white',
        'grid.linewidth': 0.0,
        'axes.grid': False,
        'axes.unicode_minus': False,
        'axes.edgecolor': 'black',
        'xtick.major.size': 8,
        'xtick.major.width': 3,
        'ytick.major.size': 8,
        'ytick.major.width': 3,
    })


## Figures ## 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:61,代碼來源:pyplot.py

示例15: xkcd

# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import xkcd [as 別名]
def xkcd(scale=1, length=100, randomness=2):
    """
    Turn on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
    This will only have effect on things drawn after this function is
    called.

    For best results, the "Humor Sans" font should be installed: it is
    not included with matplotlib.

    Parameters
    ----------
    scale : float, optional
        The amplitude of the wiggle perpendicular to the source line.
    length : float, optional
        The length of the wiggle along the line.
    randomness : float, optional
        The scale factor by which the length is shrunken or expanded.

    Notes
    -----
    This function works by a number of rcParams, so it will probably
    override others you have set before.

    If you want the effects of this function to be temporary, it can
    be used as a context manager, for example::

        with plt.xkcd():
            # This figure will be in XKCD-style
            fig1 = plt.figure()
            # ...

        # This figure will be in regular style
        fig2 = plt.figure()
    """
    if rcParams['text.usetex']:
        raise RuntimeError(
            "xkcd mode is not compatible with text.usetex = True")

    from matplotlib import patheffects
    return rc_context({
        'font.family': ['xkcd', 'xkcd Script', 'Humor Sans', 'Comic Sans MS'],
        'font.size': 14.0,
        'path.sketch': (scale, length, randomness),
        'path.effects': [patheffects.withStroke(linewidth=4, foreground="w")],
        'axes.linewidth': 1.5,
        'lines.linewidth': 2.0,
        'figure.facecolor': 'white',
        'grid.linewidth': 0.0,
        'axes.grid': False,
        'axes.unicode_minus': False,
        'axes.edgecolor': 'black',
        'xtick.major.size': 8,
        'xtick.major.width': 3,
        'ytick.major.size': 8,
        'ytick.major.width': 3,
    })


## Figures ## 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:61,代碼來源:pyplot.py


注:本文中的matplotlib.pyplot.xkcd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。