You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

使用openpyxl绘制柱状图时标题遮挡图表的问题求助

使用openpyxl绘制柱状图时标题遮挡图表的问题求助

大家好,我目前在用Python的openpyxl模块根据单元格数据动态生成柱状图,但遇到了一个麻烦:图表标题总是和柱状图的内容重叠,挡住了部分图形。

我用来创建柱状图的代码如下:

# sheet_velocity 是选中的工作表
# 图表对象
chart_velocity = BarChart()

# 数据和标签
chart_data = Reference(sheet_velocity, min_col=3, min_row=3, max_row=14)
categories = Reference(sheet_velocity, min_col=1, min_row=3, max_row=14)

chart_velocity.title = "Custom Title"
chart_velocity.title.text.rich.paragraphs[0].pPr = ParagraphProperties(defRPr=CharacterProperties(sz=1250))

man_layout = ManualLayout(xMode="edge", yMode="edge", x=0.0, y = -0.05) # 试过负值
chart_velocity.title.layout = Layout(manualLayout=man_layout)

chart_velocity.add_data(chart_data, titles_from_data=False)
chart_velocity.set_categories(categories)

# 设置数据标签
chart_velocity.dataLabels = DataLabelList()
chart_velocity.dataLabels.showVal = True # 显示数据点的值
chart_velocity.dataLabels.showSerName = False
chart_velocity.dataLabels.showCatName = False
chart_velocity.dataLabels.showLegendKey = False

chart_velocity.legend = None
chart_velocity.x_axis.delete = False
chart_velocity.y_axis.delete = False

# 设置系列样式
series = chart_velocity.series[0]
series.graphicalProperties.solidFill = "379e3e"

sheet_velocity.add_chart(chart_velocity, "F3")

我已经尝试过以下方法,但都没有效果:

  • 增大chart.height变量
  • 通过ManualLayout调整标题位置:
    • 比如设置manual_layout = ManualLayout(xMode="edge", yMode="edge", x=0.0, y=0.0),给y设正值只会让标题往下移,没法往上调整;设负值也完全没作用

有没有朋友遇到过类似的问题,或者知道怎么解决这个标题遮挡的问题呀?

内容来源于stack exchange

火山引擎 最新活动