我正在尝试使用pygal在一个图中绘制多个系列,每个系列有两个测量值(因此实际上是num_of_time_series x 2个图)。 例如,假设我的数据是:
from collections import defaultdict
measurement_1=defaultdict(None,[
("component1", [11.83, 11.35, 0.55]),
("component2", [2.19, 2.42, 0.96]),
("component3", [1.98, 2.17, 0.17])])
measurement_2=defaultdict(None,[
("component1", [34940.57, 35260.41, 370.45]),
("component2", [1360.67, 1369.58, 2.69]),
("component3", [13355.60, 14790.81, 55.63])])
x_labels=['2016-12-01', '2016-12-02', '2016-12-03']
图形渲染代码如下:
from pygal import graph
import pygal
def draw(measurement_1, measurement_2 ,x_labels):
graph = pygal.Line()
graph.x_labels = x_labels
for key, value in measurement_1.iteritems():
graph.add(key, value)
for key, value in measurement_2.iteritems():
graph.add(key, value, secondary=True)
return graph.render_data_uri()
当前结果为这个。
上面代码的问题在于不清楚哪个图表示测量1,哪个图表示测量2。 其次,我想看到每个组件用不同的颜色(或形状)表示。
此图旨在比较一个组件与另外两个组件,并查看测量1和2之间的相关性。
感谢大家的帮助!