Python matplotlib.pyplot.xkcd() Examples

The following are 30 code examples of matplotlib.pyplot.xkcd(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.pyplot , or try the search function .
Example #1
Source File: poster_PyConES2019_ENversion.py    From scikit-extremes with MIT License 6 votes vote down vote up
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 
Example #2
Source File: poster_PyConES2019_ESversion.py    From scikit-extremes with MIT License 6 votes vote down vote up
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 
Example #3
Source File: stats.py    From temci with GNU General Public License v3.0 5 votes vote down vote up
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") 
Example #4
Source File: poster_PyConES2019_ENversion.py    From scikit-extremes with MIT License 5 votes vote down vote up
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 
Example #5
Source File: poster_PyConES2019_ESversion.py    From scikit-extremes with MIT License 5 votes vote down vote up
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 
Example #6
Source File: test_path.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
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) 
Example #7
Source File: test_style.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
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 
Example #8
Source File: test_style.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
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) 
Example #9
Source File: plot.py    From pycbc with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #10
Source File: plot.py    From pycbc with GNU General Public License v3.0 5 votes vote down vote up
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.') 
Example #11
Source File: main.py    From WxConn with MIT License 5 votes vote down vote up
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' 
Example #12
Source File: test_path.py    From coffeegrindsize with MIT License 5 votes vote down vote up
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) 
Example #13
Source File: test_style.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #14
Source File: main.py    From WxConn with MIT License 5 votes vote down vote up
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() 
Example #15
Source File: test_path.py    From coffeegrindsize with MIT License 5 votes vote down vote up
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) 
Example #16
Source File: test_style.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #17
Source File: test_path.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #18
Source File: test_path.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #19
Source File: test_style.py    From coffeegrindsize with MIT License 5 votes vote down vote up
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) 
Example #20
Source File: test_style.py    From coffeegrindsize with MIT License 5 votes vote down vote up
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 
Example #21
Source File: pyplot.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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 ## 
Example #22
Source File: pyplot.py    From CogAlg with MIT License 4 votes vote down vote up
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 ## 
Example #23
Source File: pyplot.py    From coffeegrindsize with MIT License 4 votes vote down vote up
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 ## 
Example #24
Source File: pyplot.py    From twitter-stock-recommendation with MIT License 4 votes vote down vote up
def xkcd(scale=1, length=100, randomness=2):
    """
    Turns 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 ## 
Example #25
Source File: poster_PyConES2019_ESversion.py    From scikit-extremes with MIT License 4 votes vote down vote up
def make_header(title, filename, author, affiliation, width, height):
    "Create the header with the title, author(s), affiliation(s),..."
    with plt.xkcd():
        fig, ax = plt.subplots(figsize=(width, height))
        ax.set_axis_off()
        ax.text(
            0.5, 0.9,
            title,
            fontsize=45,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            0.5, 0.5,
            author,
            color='grey',
            fontsize=36,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            0.5, 0.25,
            affiliation,
            color='dimgrey',
            fontsize=32,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            -0.05, 0.9,
            'Download Poster',
            color='dimgrey',
            fontsize=20,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            -0.1, 0.8,
            'EN Version',
            color='dimgrey',
            fontsize=15,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            0, 0.8,
            'ES Version',
            color='dimgrey',
            fontsize=15,
            horizontalalignment='center',
            verticalalignment='center'
        )
        fig.savefig(filename, dpi=DPI)
        return fig 
Example #26
Source File: poster_PyConES2019_ESversion.py    From scikit-extremes with MIT License 4 votes vote down vote up
def make_XKCD_guy(
    filename,
    x=.5,
    y=.85,
    radius=.1,
    quote=None,
    color='k',
    lw=5,
    xytext=(0, 20),
    arm="left"
    ):
    # Stolen from https://alimanfoo.github.io/2016/05/31/matplotlib-xkcd.html
    fig, ax = plt.subplots(figsize=(10, 15))
    ax.set_axis_off()

    # draw the head
    head = plt.Circle((x, y), radius=radius, edgecolor=color, lw=lw,
                      facecolor='none', zorder=10)
    ax.add_patch(head)
    # draw the body
    body = plt.Line2D([x, x], [y-radius, y-(radius * 4)], 
                      color=color, lw=lw, transform=ax.transAxes)
    ax.add_line(body)
    # draw the arms
    if arm == 'left':
        arm1 = plt.Line2D([x, x+(4*radius)], [y-(radius * 1.5), y-(radius)],
                          color=color, lw=lw, transform=ax.transAxes)
        ax.add_line(arm1)
        arm2 = plt.Line2D([x, x-(radius * .8)], [y-(radius * 1.5), y-(radius*5)],
                          color=color, lw=lw, transform=ax.transAxes)
        ax.add_line(arm2)
    if arm == "right":
        arm1 = plt.Line2D([x, x-(4*radius)], [y-(radius * 1.5), y-(radius)],
                          color=color, lw=lw, transform=ax.transAxes)
        ax.add_line(arm1)
        arm2 = plt.Line2D([x, x+(radius * .8)], [y-(radius * 1.5), y-(radius*5)],
                          color=color, lw=lw, transform=ax.transAxes)
        ax.add_line(arm2)
    # draw the legs
    leg1 = plt.Line2D([x, x+(radius)], [y-(radius * 4), y-(radius*8)], 
                      color=color, lw=lw, transform=ax.transAxes)
    ax.add_line(leg1)
    leg2 = plt.Line2D([x, x-(radius*.5)], [y-(radius * 4), y-(radius*8)], 
                      color=color, lw=lw, transform=ax.transAxes)
    ax.add_line(leg2)

    fig.savefig(filename, transparent=True, dpi=DPI)
    return fig 
Example #27
Source File: pyplot.py    From GraphicDesignPatternByPython with MIT License 4 votes vote down vote up
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 ## 
Example #28
Source File: pyplot.py    From matplotlib-4-abaqus with MIT License 4 votes vote down vote up
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 ## 
Example #29
Source File: poster_PyConES2019_ENversion.py    From scikit-extremes with MIT License 4 votes vote down vote up
def make_header(title, filename, author, affiliation, width, height):
    "Create the header with the title, author(s), affiliation(s),..."
    with plt.xkcd():
        fig, ax = plt.subplots(figsize=(width, height))
        ax.set_axis_off()
        ax.text(
            0.5, 0.9,
            title,
            fontsize=46,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            0.5, 0.5,
            author,
            color='grey',
            fontsize=36,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            0.5, 0.25,
            affiliation,
            color='dimgrey',
            fontsize=32,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            -0.05, 0.9,
            'Download Poster',
            color='dimgrey',
            fontsize=20,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            -0.1, 0.8,
            'EN Version',
            color='dimgrey',
            fontsize=15,
            horizontalalignment='center',
            verticalalignment='center'
        )
        ax.text(
            0, 0.8,
            'ES Version',
            color='dimgrey',
            fontsize=15,
            horizontalalignment='center',
            verticalalignment='center'
        )
        fig.savefig(filename, dpi=DPI)
        return fig 
Example #30
Source File: pyplot.py    From Computable with MIT License 4 votes vote down vote up
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 ##