You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pygal问题:如何为不同线条设置不同的描边宽度?

Pygal设置不同线条粗细的正确方法

在Pygal中,你通过stroke_style的width属性设置线条粗细不生效,是因为线条粗细由独立的stroke_width参数控制,而非stroke_style字典内的属性。stroke_style主要用于定义线条样式(如虚线、颜色等),粗细需要单独指定。

修改后的代码如下:

import pygal

chart = pygal.XY()
chart.add(**{'title': 'Line A', 'values': [(1, 1), (10, 10)]})
chart.add(**{'title': 'Line B', 'values': [(1, 2), (10, 20)], 'stroke_style': {'dasharray': '3, 6'}})
chart.add(**{'title': 'Line C', 'values': [(1, 3), (10, 30)], 'stroke_width': 5})

chart.render_to_png('chart.png')

修改后,Line C的线条会按照设置的5像素显示粗线,同时Line B的虚线样式依然正常生效。

内容的提问来源于stack exchange,提问作者tikka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 07:07:15