本文整理汇总了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
示例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
示例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'
示例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()
示例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)
示例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
示例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)
示例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)
示例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")
示例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.')
示例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)
示例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
示例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 ##
示例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 ##
示例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 ##