[英]Subplot of tables in pylab
我正在寻找一种方法来创建包含几个子图的表格。 让我试着解释我在说什么。 下面是一个有几个子图的图,这些子图是imshow
图。 我想要完全相同的数字,但不是“imshow”图,而是我想要表,只是普通表。 在我的例子中,他们只显示值1和2:
[1, 2]
[2, 1]
我该怎么做?
先感谢您
这是我用来生成图表的代码。
import pylab
import numpy as np
x = np.array([[1,2],[2,1]])
fig = pylab.figure()
fig_list = []
for i in xrange(5):
fig_list.append( fig.add_subplot(2,3,i+1) )
fig_list[i] = pylab.imshow(x)
pylab.savefig('my_fig.pdf')
pylab.show()
您可以使用pylab.table命令, 此处提供的文档。
例如:
import pylab
import numpy as np
x = [[1,2],[2,1]]
fig = pylab.figure()
axes_list = []
table_list = []
for i in xrange(5):
axes_list.append( fig.add_subplot(2,3,i+1) )
axes_list[i].set_xticks([])
axes_list[i].set_yticks([])
axes_list[i].set_frame_on(False)
table_list.append(pylab.table(cellText=x,colLabels = ['col']*2,rowLabels=['row']*2,colWidths = [0.3]*2,loc='center'))
pylab.savefig('my_fig.pdf')
pylab.show()
我还创建了一个额外的列表变量,并重命名为fig_list,因为轴实例被绘制对象的实例覆盖。 现在您可以访问这两个句柄。
其他有用的命令包括:
# Specify a title for the plot
axes_list[i].set_title('test')
# Specify the axes size and position
axes_list[i].set_position([left, bottom, width, height])
# The affect of the above set_position can be seen by turning the axes frame on, like so:
axes_list[i].set_frame_on(True)
文档:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.