python-matplotlib-创建一个多行图,其下面是结果摘要
我正在用python开发多行图的自动化。 下面是我将在excel中手动创建的示例 我目前的代码如下:python-matplotlib-创建一个多行图,其下面是结果摘要,python,graph,matplotlib,Python,Graph,Matplotlib,我正在用python开发多行图的自动化。 下面是我将在excel中手动创建的示例 我目前的代码如下: plt = pyplot plt.plot(channel_list, udp_dl_values, label="UDP DL") plt.plot(channel_list, tcp_dl_values, label="TCP DL") plt.plot(channel_list, udp_ul_values, label="UDP UL") plt
plt = pyplot
plt.plot(channel_list, udp_dl_values, label="UDP DL")
plt.plot(channel_list, tcp_dl_values, label="TCP DL")
plt.plot(channel_list, udp_ul_values, label="UDP UL")
plt.plot(channel_list, tcp_ul_values, label="TCP UL")
plt.grid()
import numpy as np
import matplotlib.pyplot as plt
#Create a figure and axes with room for the table
fig = plt.figure()
ax = plt.axes([0.2, 0.2, 0.7, 0.6])
#Create labels for the rows and columns as tuples
colLabels = ('36', '40', '44', '48', '149', '153', '157', '161', '165')
rowLabels = ('UDL DL', 'UDP UL', 'TCP DL', 'TCP UL')
#Table data as a numpy array
tableData = np.array([[ 36.7128, 37.684, 38.283, 48.425, 32.839, 36.424, 34.440, 31.642, 35.710],
[ 36.7128, 37.684, 38.283, 48.425, 32.839, 36.424, 34.440, 31.642, 35.710],
[ 36.7128, 37.684, 38.283, 48.425, 32.839, 36.424, 34.440, 31.642, 35.710],
[ 36.7128, 37.684, 38.283, 48.425, 32.839, 36.424, 34.440, 31.642, 35.710]])
#Get the current color cycle as a list, then reset the cycle to be at the beginning
colors = []
while True:
colors.append(ax._get_lines.color_cycle.next())
if colors[0] == colors[-1] and len(colors)>1:
colors.pop(-1)
break
for i in xrange(len(colors)-1):
ax._get_lines.color_cycle.next()
#Show the table
table = plt.table(cellText=tableData,
rowLabels=rowLabels, rowColours=colors,
colLabels=colLabels,
loc='bottom')
#Make some line plots
x = np.linspace(0,10,100)
ax.plot(x,np.sin(x))
ax.plot(x,-1*np.sin(x))
ax.plot(x,np.cos(x))
ax.plot(x,-1*np.cos(x))
#Turn off x-axis ticks and show the plot
plt.xticks([])
plt.show()
我想知道我是否可以使用脚本创建上述内容
谢谢
第三方
这里有什么问题吗?您几乎肯定需要将图形生成为图像,然后导入并使用其中一个gui工具包(wx/TK/qt/etc)将图像放在窗口中,并将表格放在下面(有些琐碎)。。。或者,可以查看win32 api和xcom对象,直接与excel对话,让excel为您完成这项工作(非常重要),也可以不看谢谢,但有一个问题,在这个例子中,yoff的用途是什么?@ParthG我认为这是x轴标签的偏移量,可以将每一行进一步向下推。@PaulH我似乎无法使该属性在直线绘图上工作。感谢发布这个例子,我能够得到我想要的。
import numpy as np
import matplotlib.pyplot as plt
#Create a figure and axes with room for the table
fig = plt.figure()
ax = plt.axes([0.2, 0.2, 0.7, 0.6])
#Create labels for the rows and columns as tuples
colLabels = ('36', '40', '44', '48', '149', '153', '157', '161', '165')
rowLabels = ('UDL DL', 'UDP UL', 'TCP DL', 'TCP UL')
#Table data as a numpy array
tableData = np.array([[ 36.7128, 37.684, 38.283, 48.425, 32.839, 36.424, 34.440, 31.642, 35.710],
[ 36.7128, 37.684, 38.283, 48.425, 32.839, 36.424, 34.440, 31.642, 35.710],
[ 36.7128, 37.684, 38.283, 48.425, 32.839, 36.424, 34.440, 31.642, 35.710],
[ 36.7128, 37.684, 38.283, 48.425, 32.839, 36.424, 34.440, 31.642, 35.710]])
#Get the current color cycle as a list, then reset the cycle to be at the beginning
colors = []
while True:
colors.append(ax._get_lines.color_cycle.next())
if colors[0] == colors[-1] and len(colors)>1:
colors.pop(-1)
break
for i in xrange(len(colors)-1):
ax._get_lines.color_cycle.next()
#Show the table
table = plt.table(cellText=tableData,
rowLabels=rowLabels, rowColours=colors,
colLabels=colLabels,
loc='bottom')
#Make some line plots
x = np.linspace(0,10,100)
ax.plot(x,np.sin(x))
ax.plot(x,-1*np.sin(x))
ax.plot(x,np.cos(x))
ax.plot(x,-1*np.cos(x))
#Turn off x-axis ticks and show the plot
plt.xticks([])
plt.show()