将贝塞尔曲线轴添加到Matplotlib图 [英] Adding bezier axes to matplotlib figure
问题描述
使用 bezier 库时,Curve.plot()函数将返回AxesSubplot对象
When using the bezier library, the Curve.plot() function returns an AxesSubplot object
nodes1 = np.array([[0.0, 0.0],[0.625, .75], [1.0, 1.0]])
curve1 = bezier.Curve(nodes1, degree=2)
ax = curve1.plot(num_pts=256)
print ax
返回一个
AxesSubplot(0.125,0.11;0.775x0.77)
我知道创建子图的典型方法是
I know the typical way of creating a subplot is with
fig = pyplot.figure()
ax = fig.add_subplot(111)
但是我找不到任何有关在图形上添加已经创建的子图的文档.
but I can't find any documentation on adding an already created subplot to a figure.
我可以使用plt.show()显示子图,但无法访问该图.如果尝试使用plt.figure()创建图形,则会显示两个不同的图形(在不同的窗口中).
I can display the subplot with plt.show() but can't access the figure. If I try to create a figure with plt.figure(), two different figures (in different windows) are displayed.
推荐答案
首先,要避免打开另一个窗口,必须关闭"绘图:
First, to avoid another window to open you must "close" the plotting:
pyplot.close()
然后您可以执行
ax = curve1.plot(num_pts=256)
现在,我不知道为什么要引入子图(111),该图仍然使用整个窗口(单个图).但是,如果您仍然想使用较小的子图(例如221),则可以执行以下操作:
Now, I don't know why do you bring in subplot(111), which uses the whole window anyway (single figure). But if you still want to use a smaller subplot (e.g. 221), you can do the following:
pyplot.close()
fig = pyplot.figure()
#fig = pyplot.gcf(); # This will also do
ax = fig.add_subplot(221); curve.plot(num_pts=256,ax=ax)
(注意:我只是测试了这两种情况,它们都起作用.只有我使用2D节点而不是3D.)
(Note: I just tested both cases and they work. Only I used 2D nodes instead of 3D.)
这篇关于将贝塞尔曲线轴添加到Matplotlib图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!