[Python] Chart Title is in middle/between my bar graph plotted using openpyxl BarChart module

Discussão em 'Python' iniciado por Stack, Julho 28, 2025.

  1. Stack

    Stack Membro Participativo

    I am using openpyxl (python module) to dynamically plot a bar graph with data from respective cells, but the chart title gets in between my bar graph.

    Code used to create the bar graph:

    #sheet_velocity is the worksheet selected

    # Chart object
    chart_velocity = BarChart()

    # Data and labels
    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) #tried -ve value
    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 # Show the value of the data point
    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")


    [​IMG]

    Things that I've tried so far (have not worked):


    1. Increasing the chart.height variable


    2. Changing the position of chart title using ManualLayout

      For example: manual_layout = ManualLayout(xMode="edge", yMode="edge", x=0.0, y=0.0)

    (Giving a +ve value to y would bring the title down but not move it up, tried -ve value as well --> did not work.)

    Continue reading...

Compartilhe esta Página