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

2024-06-25 04:38:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用pygal在一个图形中绘制两个测量值的多个系列(因此实际上是“时间序列x2图的num_”)。 例如,假设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']

图形呈现代码是:

^{pr2}$

当前结果是that。在

上面代码中的问题是,不清楚哪个图表示度量1,哪个表示度量2。 第二,我想看到每个组件在不同的颜色(或形状)。在

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

谢谢你们的帮助!在


Tags: 代码none图形度量时间绘制组件序列
1条回答
网友
1楼 · 发布于 2024-06-25 04:38:40

我想出了如何用虚线区分比较的分量。代码应该是这样的:

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

相关问题 更多 >