我正试图离开matlab,转而使用python+matplotlib。然而,我还没有真正弄清楚matplotlib等价于matlab的“handles”是什么。这里有一些matlab代码,我在这里返回句柄,这样我就可以更改某些属性。这段代码使用matplotlib的确切等价物是什么?我经常在matlab中使用句柄的“Tag”属性,并使用“findobj”。这也可以用matplotlib实现吗?在
% create figure and return figure handle
h = figure();
% add a plot and tag it so we can find the handle later
plot(1:10, 1:10, 'Tag', 'dummy')
% add a legend
my_legend = legend('a line')
% change figure name
set(h, 'name', 'myfigure')
% find current axes
my_axis = gca();
% change xlimits
set(my_axis, 'XLim', [0 5])
% find the plot object generated above and modify YData
set(findobj('Tag', 'dummy'), 'YData', repmat(10, 1, 10))
还有一个findobj方法也是matplotlib:
注意,
plt.plot
中的gid
参数通常由matplotlib使用(仅当后端设置为“svg”时)。它使用gid
作为某些分组元素的id
属性(比如line2d
,patch
,text
)。在我没有用过matlab,但我想这是你想要的
当然,这只是一个基本的情节,还有更多的去吧。去吧尽管this找到您想要的图形并查看其源代码。在
相关问题 更多 >
编程相关推荐