本文整理汇总了Python中matplotlib.pyplot.table方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.table方法的具体用法?Python pyplot.table怎么用?Python pyplot.table使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.table方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_compare_table
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def plot_compare_table(image_list, method_list, color_list, compare_dict, fig_name="", fig_num=111):
"""绘制了对比表格."""
row_labels = image_list
# 写入值:
table_vals = []
for i in range(len(row_labels)):
row_vals = []
for method in method_list:
row_vals.append(compare_dict[method][i])
table_vals.append(row_vals)
# 绘制表格图
colors = [[(0.95, 0.95, 0.95) for c in range(len(method_list))] for r in range(len(row_labels))] # cell的颜色
# plt.figure(figsize=(8, 4), dpi=120)
plt.subplot(fig_num)
plt.title(fig_name) # 绘制标题
lightgrn = (0.5, 0.8, 0.5) # 这个是label的背景色
plt.table(cellText=table_vals,
rowLabels=row_labels,
colLabels=method_list,
rowColours=[lightgrn] * len(row_labels),
colColours=color_list,
cellColours=colors,
cellLoc='center',
loc='upper left')
plt.axis('off') # 关闭坐标轴
示例2: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def plot(self):
print(self.policy)
plt.figure()
plt.xlim(0, MAX_CARS + 1)
plt.ylim(0, MAX_CARS + 1)
plt.table(cellText=np.flipud(self.policy), loc=(0, 0), cellLoc='center')
plt.show()
开发者ID:ShangtongZhang,项目名称:reinforcement-learning-an-introduction,代码行数:9,代码来源:car_rental_synchronous.py
示例3: test_zorder
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def test_zorder():
data = [[66386, 174296],
[58230, 381139]]
colLabels = ('Freeze', 'Wind')
rowLabels = ['%d year' % x for x in (100, 50)]
cellText = []
yoff = np.array([0.0] * len(colLabels))
for row in reversed(data):
yoff += row
cellText.append(['%1.1f' % (x/1000.0) for x in yoff])
t = np.linspace(0, 2*np.pi, 100)
plt.plot(t, np.cos(t), lw=4, zorder=2)
plt.table(cellText=cellText,
rowLabels=rowLabels,
colLabels=colLabels,
loc='center',
zorder=-2,
)
plt.table(cellText=cellText,
rowLabels=rowLabels,
colLabels=colLabels,
loc='upper center',
zorder=4,
)
plt.yticks([])
示例4: test_label_colours
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def test_label_colours():
dim = 3
c = np.linspace(0, 1, dim)
colours = plt.cm.RdYlGn(c)
cellText = [['1'] * dim] * dim
fig = plt.figure()
ax1 = fig.add_subplot(4, 1, 1)
ax1.axis('off')
ax1.table(cellText=cellText,
rowColours=colours,
loc='best')
ax2 = fig.add_subplot(4, 1, 2)
ax2.axis('off')
ax2.table(cellText=cellText,
rowColours=colours,
rowLabels=['Header'] * dim,
loc='best')
ax3 = fig.add_subplot(4, 1, 3)
ax3.axis('off')
ax3.table(cellText=cellText,
colColours=colours,
loc='best')
ax4 = fig.add_subplot(4, 1, 4)
ax4.axis('off')
ax4.table(cellText=cellText,
colColours=colours,
colLabels=['Header'] * dim,
loc='best')
示例5: test_bbox_inches_tight
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def test_bbox_inches_tight():
#: Test that a figure saved using bbox_inches='tight' is clipped correctly
data = [[ 66386, 174296, 75131, 577908, 32015],
[ 58230, 381139, 78045, 99308, 160454],
[ 89135, 80552, 152558, 497981, 603535],
[ 78415, 81858, 150656, 193263, 69638],
[139361, 331509, 343164, 781380, 52269]]
colLabels = rowLabels = [''] * 5
rows = len(data)
ind = np.arange(len(colLabels)) + 0.3 # the x locations for the groups
cellText = []
width = 0.4 # the width of the bars
yoff = np.array([0.0] * len(colLabels))
# the bottom values for stacked bar chart
fig, ax = plt.subplots(1, 1)
for row in xrange(rows):
plt.bar(ind, data[row], width, bottom=yoff)
yoff = yoff + data[row]
cellText.append([''])
plt.xticks([])
plt.legend([''] * 5, loc=(1.2, 0.2))
# Add a table at the bottom of the axes
cellText.reverse()
the_table = plt.table(cellText=cellText,
rowLabels=rowLabels,
colLabels=colLabels, loc='bottom')
示例6: plot_op
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def plot_op(ops, path, width=[], head_width=None, F_base=16):
assert len(width) == 0 or len(width) == len(ops) - 1
table_vals = []
scales = {0: "1/8", 1: "1/16", 2: "1/32"}; base_scale = 3
for idx, op in enumerate(ops):
scale = path[idx]
if len(width) > 0:
if idx < len(width):
ch = int(F_base*2**(scale+base_scale)*width[idx])
else:
ch = int(F_base*2**(scale+base_scale)*head_width)
else:
ch = F_base*2**(scale+base_scale)
row = [idx+1, PRIMITIVES[op], scales[scale], ch]
table_vals.append(row)
# Based on http://stackoverflow.com/a/8531491/190597 (Andrey Sobolev)
col_labels = ['Stage', 'Operator', 'Scale', '#Channel_out']
plt.tight_layout()
fig = plt.figure(figsize=(3,3))
ax = fig.add_subplot(111, frame_on=False)
ax.xaxis.set_visible(False) # hide the x axis
ax.yaxis.set_visible(False) # hide the y axis
table = plt.table(cellText=table_vals,
colWidths=[0.22, 0.6, 0.25, 0.5],
colLabels=col_labels,
cellLoc='center',
loc='center')
table.auto_set_font_size(False)
table.set_fontsize(20)
table.scale(2, 2)
return fig
示例7: test_non_square
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def test_non_square():
# Check that creating a non-square table works
cellcolors = ['b', 'r']
plt.table(cellColours=cellcolors)
示例8: test_zorder
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def test_zorder():
data = [[66386, 174296],
[58230, 381139]]
colLabels = ('Freeze', 'Wind')
rowLabels = ['%d year' % x for x in (100, 50)]
cellText = []
yoff = np.zeros(len(colLabels))
for row in reversed(data):
yoff += row
cellText.append(['%1.1f' % (x/1000.0) for x in yoff])
t = np.linspace(0, 2*np.pi, 100)
plt.plot(t, np.cos(t), lw=4, zorder=2)
plt.table(cellText=cellText,
rowLabels=rowLabels,
colLabels=colLabels,
loc='center',
zorder=-2,
)
plt.table(cellText=cellText,
rowLabels=rowLabels,
colLabels=colLabels,
loc='upper center',
zorder=4,
)
plt.yticks([])
示例9: test_diff_cell_table
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def test_diff_cell_table():
cells = ('horizontal', 'vertical', 'open', 'closed', 'T', 'R', 'B', 'L')
cellText = [['1'] * len(cells)] * 2
colWidths = [0.1] * len(cells)
_, axes = plt.subplots(nrows=len(cells), figsize=(4, len(cells)+1))
for ax, cell in zip(axes, cells):
ax.table(
colWidths=colWidths,
cellText=cellText,
loc='center',
edges=cell,
)
ax.axis('off')
plt.tight_layout()
示例10: test_bbox_inches_tight
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def test_bbox_inches_tight():
#: Test that a figure saved using bbox_inches='tight' is clipped correctly
data = [[66386, 174296, 75131, 577908, 32015],
[58230, 381139, 78045, 99308, 160454],
[89135, 80552, 152558, 497981, 603535],
[78415, 81858, 150656, 193263, 69638],
[139361, 331509, 343164, 781380, 52269]]
colLabels = rowLabels = [''] * 5
rows = len(data)
ind = np.arange(len(colLabels)) + 0.3 # the x locations for the groups
cellText = []
width = 0.4 # the width of the bars
yoff = np.zeros(len(colLabels))
# the bottom values for stacked bar chart
fig, ax = plt.subplots(1, 1)
for row in range(rows):
ax.bar(ind, data[row], width, bottom=yoff, align='edge', color='b')
yoff = yoff + data[row]
cellText.append([''])
plt.xticks([])
plt.legend([''] * 5, loc=(1.2, 0.2))
# Add a table at the bottom of the axes
cellText.reverse()
the_table = plt.table(cellText=cellText,
rowLabels=rowLabels,
colLabels=colLabels, loc='bottom')
示例11: generate_tabular_sample
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def generate_tabular_sample(cls, dataset_name, dataset_class, data_location, sample_location):
"""
Generates a jpg from a sample of the pandas DataFrame
"""
extract_loc = '%sraw/%s' % (data_location, 'sample_extract')
file_to_extract = dataset_class.data_file
_ = cls.extract_data_files(dataset_name, dataset_class, data_location, sample_location, extract_loc, None)
# define the core DataFrames
file_type = file_to_extract.split('.')[-1]
if file_type == 'csv':
df = pd.read_csv('%s/%s' % ('%s%s' % (data_location, 'raw/sample_extract'), file_to_extract)).head()
else:
df = pd.DataFrame()
plt.figure()
cell_text = []
for row in range(len(df)):
cell_text.append(df.iloc[row, :3])
plt.table(cellText=cell_text, colLabels=df.columns[:3], loc='center')
plt.axis('off')
plt.savefig(sample_location)
shutil.rmtree(extract_loc)
示例12: test_bbox_inches_tight
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def test_bbox_inches_tight():
#: Test that a figure saved using bbox_inches='tight' is clipped correctly
data = [[66386, 174296, 75131, 577908, 32015],
[58230, 381139, 78045, 99308, 160454],
[89135, 80552, 152558, 497981, 603535],
[78415, 81858, 150656, 193263, 69638],
[139361, 331509, 343164, 781380, 52269]]
colLabels = rowLabels = [''] * 5
rows = len(data)
ind = np.arange(len(colLabels)) + 0.3 # the x locations for the groups
cellText = []
width = 0.4 # the width of the bars
yoff = np.zeros(len(colLabels))
# the bottom values for stacked bar chart
fig, ax = plt.subplots(1, 1)
for row in range(rows):
ax.bar(ind, data[row], width, bottom=yoff, color='b')
yoff = yoff + data[row]
cellText.append([''])
plt.xticks([])
plt.legend([''] * 5, loc=(1.2, 0.2))
# Add a table at the bottom of the axes
cellText.reverse()
the_table = plt.table(cellText=cellText,
rowLabels=rowLabels,
colLabels=colLabels, loc='bottom')
示例13: test_auto_column
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def test_auto_column():
fig = plt.figure()
# iterable list input
ax1 = fig.add_subplot(4, 1, 1)
ax1.axis('off')
tb1 = ax1.table(cellText=[['Fit Text', 2],
['very long long text, Longer text than default', 1]],
rowLabels=["A", "B"],
colLabels=["Col1", "Col2"],
loc="center")
tb1.auto_set_font_size(False)
tb1.set_fontsize(12)
tb1.auto_set_column_width([-1, 0, 1])
# iterable tuple input
ax2 = fig.add_subplot(4, 1, 2)
ax2.axis('off')
tb2 = ax2.table(cellText=[['Fit Text', 2],
['very long long text, Longer text than default', 1]],
rowLabels=["A", "B"],
colLabels=["Col1", "Col2"],
loc="center")
tb2.auto_set_font_size(False)
tb2.set_fontsize(12)
tb2.auto_set_column_width((-1, 0, 1))
#3 single inputs
ax3 = fig.add_subplot(4, 1, 3)
ax3.axis('off')
tb3 = ax3.table(cellText=[['Fit Text', 2],
['very long long text, Longer text than default', 1]],
rowLabels=["A", "B"],
colLabels=["Col1", "Col2"],
loc="center")
tb3.auto_set_font_size(False)
tb3.set_fontsize(12)
tb3.auto_set_column_width(-1)
tb3.auto_set_column_width(0)
tb3.auto_set_column_width(1)
#4 non integer interable input
ax4 = fig.add_subplot(4, 1, 4)
ax4.axis('off')
tb4 = ax4.table(cellText=[['Fit Text', 2],
['very long long text, Longer text than default', 1]],
rowLabels=["A", "B"],
colLabels=["Col1", "Col2"],
loc="center")
tb4.auto_set_font_size(False)
tb4.set_fontsize(12)
tb4.auto_set_column_width("-101")
示例14: plotHITStatus
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import table [as 别名]
def plotHITStatus( savePath = '/home/ubuntu/amt_guis/cocoa_depth/plots/', filename = 'time_info' ):
pdf = PdfPages( savePath + filename + '.pdf')
fig = plt.figure()
plt.clf()
page_size = 100
ass_time_info_list = []
mtc = MTurkConnection( host = _host )
assignments = getReviewableAssignments()
for ass in assignments:
time_info = \
{'AcceptTime':ass.AcceptTime,
'SubmitTime':ass.SubmitTime,
'ExecutionTime': [ question_form_answer.fields[0] for question_form_answer in ass.answers[0] if question_form_answer.qid == '_hit_rt' ][0] }
ass_time_info_list.append( time_info )
ass_time_info_list.sort(key=lambda x: datetime.datetime.strptime(x['AcceptTime'],'%Y-%m-%dT%H:%M:%SZ'))
first_assignment = ass_time_info_list[0]
ass_time_info_list.sort(key=lambda x: datetime.datetime.strptime(x['SubmitTime'],'%Y-%m-%dT%H:%M:%SZ'))
last_assignment = ass_time_info_list[-1]
time_since_beginning = int(( datetime.datetime.strptime(last_assignment['SubmitTime'],'%Y-%m-%dT%H:%M:%SZ') - datetime.datetime.strptime(first_assignment['AcceptTime'],'%Y-%m-%dT%H:%M:%SZ')).total_seconds())
completed_percentage = []
# time since beginning in one hour intervals
time_range = range( 0, time_since_beginning + 3600, 3600 )
for s in time_range:
currently_completed = \
[x for x in ass_time_info_list if datetime.datetime.strptime(x['SubmitTime'],'%Y-%m-%dT%H:%M:%SZ') < datetime.timedelta(seconds=s) + datetime.datetime.strptime(first_assignment['SubmitTime'],'%Y-%m-%dT%H:%M:%SZ')]
perc = len( currently_completed ) / float( NUMBER_HITS * NUMBER_HIT_ASSIGNMENTS )
completed_percentage.append( perc )
per_hour_completion_rate = len(ass_time_info_list) / float(time_since_beginning / 3600)
#print per_hour_completion_rate
hours_to_completion = ((NUMBER_HITS * NUMBER_HIT_ASSIGNMENTS) - len(ass_time_info_list)) / per_hour_completion_rate
#print hours_to_completion
plt.plot( time_range, completed_percentage )
rows = ['Completed Assignments','Total Assignments','Hour Completion Rate','Hours to Completion']
data = [["%d"%(len(ass_time_info_list))],["%d"%(NUMBER_HITS * NUMBER_HIT_ASSIGNMENTS)],["%.2f" % per_hour_completion_rate],["%.2f" % hours_to_completion]]
plt.table(cellText=data,rowLabels=rows,loc='center',colWidths = [0.1]*3)
plt.title('Per hour completion percentage')
plt.xticks( time_range[0::10], [str(x/3600) for x in time_range[0::10]] )
plt.yticks([0,0.2,0.4,0.6,0.8,1],['0%', '20%','40%','60%','80%','100%'])
plt.ylabel('Completion Percentage')
plt.xlabel('Hours since beginning of task')
plt.grid()
pdf.savefig()
pdf.close()
plt.close()