Mai*_*lam 16 python matplotlib
plt.figure(figsize=(10,8))
plt.scatter(df['attacker_size'][df['year'] == 298],
# attacker size in year 298 as the y axis
df['defender_size'][df['year'] == 298],
# the marker as
marker='x',
# the color
color='b',
# the alpha
alpha=0.7,
# with size
s = 124,
# labelled this
label='Year 298')
Run Code Online (Sandbox Code Playgroud)
在上面从Matplotlib的Scatterplot收集的代码片段中,有什么必要plt.figure()?
Mai*_*lam 11
使用的目的plt.figure()是创建一个图形对象。
整个人物被视为人物对象。plt.figure()当我们想要调整图形的大小以及想要在单个图形中添加多个Axes对象时,必须显式使用。
# in order to modify the size
fig = plt.figure(figsize=(12,8))
# adding multiple Axes objects
fig, ax_lst = plt.subplots(2, 2) # a figure with a 2x2 grid of Axes
Run Code Online (Sandbox Code Playgroud)
Sue*_*ver 10
它并不总是必要的,因为 afigure是在您创建scatter绘图时隐式创建的;但是,在您显示的情况下,图形是显式创建的plt.figure,因此图形将是特定大小而不是默认大小。
另一种选择是gcf在创建scatter绘图后使用获取当前图形并追溯设置图形大小:
# Create scatter plot here
plt.gcf().set_size_inches(10, 8)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33289 次 |
| 最近记录: |