如何使用pygal在一个图表中绘制多个图表?

How to plot multiple graphs in one chart using pygal?

我正在尝试使用 pygal 在一个图中绘制具有两个测量值的多个系列(因此它实际上是 num_of_time_series x 2 图)。 例如,假设 mt 数据是:

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()

当前结果为that。

上面代码中的问题是不清楚哪个图形表示测量 1,哪个图形表示测量 2。 其次,我希望看到每个组件都有不同的颜色(或形状)。

此图旨在将一个组件与其他两个组件进行比较,并查看测量值 1 和测量值 2 之间的相关性。

感谢大家的帮助!

我想出了如何用虚线区分比较的组件。代码应如下所示:

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():
     ##
     if "component1":
        graph.add(key, value, stroke_style={'width': 5, 'dasharray': '3, 6', 'linecap': 'round', 'linejoin': 'round'})
     else:
     ##
        graph.add(key, value)
  for key, value in measurement_2.iteritems():
      graph.add(key, value, secondary=True)

  return graph.render_data_uri()