reportlab的图设置主题色
使用ReportLab创建图表时,可以通过设置颜色来定义主题色。可以使用RGB颜色或HTML颜色代码来定义颜色。以下是一个示例:
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.lib import colors
# 定义主题色
theme_color = colors.HexColor('#1f77b4')
# 创建图表
data = [(1, 2, 3, 4), (2, 3, 4, 5), (3, 4, 5, 6)]
drawing = Drawing(400, 200)
chart = VerticalBarChart()
chart.x = 50
chart.y = 50
chart.width = 300
chart.height = 100
chart.data = data
chart.strokeColor = colors.black
chart.fillColor = theme_color
drawing.add(chart)
# 保存图表
drawing.save(formats=['pdf'], outDir='.', fnRoot='chart')
在上面的示例中,我们使用colors.HexColor()方法创建一个RGB颜色对象,并将其赋值给theme_color变量。然后,我们将fillColor属性设置为theme_color,这样图表的颜色就会被设置为主题色
原文地址: http://www.cveoy.top/t/topic/hld3 著作权归作者所有。请勿转载和采集!