from mpl_toolkits.axisartist.axislines import SubplotZero
import matplotlib.pyplot as plt
import numpy as np
if 1:
fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
for direction in ["xzero", "yzero"]:
# adds arrows at the ends of each axis
ax.axis[direction].set_axisline_style("-|>, size=4") # < - modified here
# adds X and Y-axis from the origin
ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
# hides borders
ax.axis[direction].set_visible(False)
x = np.linspace(-0.5, 1., 100)
ax.plot(x, np.sin(x*np.pi))
plt.show()
%matplotlib notebook
from mpl_toolkits.axisartist.axislines import SubplotZero
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
for direction in ["xzero", "yzero"]:
# adds arrows at the ends of each axis
ax.axis[direction].set_axisline_style("-|>", size=5)
# adds X and Y-axis from the origin
ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
# hides borders
ax.axis[direction].set_visible(False)
x = np.linspace(-0.5, 1., 100)
ax.plot(x, np.sin(x*np.pi))
plt.show()
# Cell 1
%matplotlib inline
%config InlineBackend.print_figure_kwargs = {'bbox_inches':None}
# Cell 2
import matplotlib.pyplot as plt
plt.rcdefaults()
from mpl_toolkits.axisartist.axislines import SubplotZero
import numpy as np
fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
for direction in ["xzero", "yzero"]:
# adds arrows at the ends of each axis
ax.axis[direction].set_axisline_style("-|>", size=5)
# adds X and Y-axis from the origin
ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
# hides borders
ax.axis[direction].set_visible(False)
x = np.linspace(-0.5, 1., 100)
ax.plot(x, np.sin(x*np.pi))
plt.show()
size
参数必须在引号内。在逗号后的引号外传递。使用以下命令来自official website的完整代码
这个问题与jupyter笔记本及其内联后端的使用有关。因此,如果使用
%matplotlib notebook
后端,您将获得正确的输出。(为此,需要重新启动内核。)如果您想/需要使用
%matplotlib inline
后端,您可能需要还原一些设置,这样箭头就不会从图形中裁剪出来。你知道吗创建png图形的默认设置是使用
bbox_inches="tight"
选项。这可以通过默认地物大小、dpi和子地块参数are different。恢复这些可以通过
由于Iypthon中的a bug,rcParameters不应设置在笔记本的第一个单元格中。你知道吗
因此
相关问题 更多 >
编程相关推荐