mackinleyhills
mackinleyhills

Reputation: 31

How remove axis lines in clustered bar chart using python-pptx?

This is the sample code that I have to produce the chart (image linked below).

x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
graphic_frame = slide.shapes.add_chart(
    XL_CHART_TYPE.BAR_CLUSTERED, x, y, cx, cy, chart_data
)

chart = graphic_frame.chart

chart.chart_title.has_text_frame=True
chart.chart_title.text_frame.text= "1_TRS_Year"
chart.chart_style = 1
    
    
plot = chart.plots[0]
plot.has_data_labels = True
data_labels = plot.data_labels
    
data_labels.font.size = Pt(9)
data_labels.font.color.rgb = RGBColor(0,0,0)
data_labels.number_format = '0%'
data_labels.position = XL_LABEL_POSITION.OUTSIDE_END

category_axis.has_major_gridlines = False
category_axis.has_minor_gridlines = False
category_axis.minor_tick_mark = XL_TICK_MARK.OUTSIDE
category_axis.tick_labels.font.italic = False
category_axis.tick_labels.font.size = Pt(12)
category_axis.tick_label_position = XL_TICK_LABEL_POSITION.LOW
    
    
value_axis = chart.value_axis
value_axis.has_major_gridlines = False
value_axis.has_minor_gridlines = False
    
value_axis.minor_tick_mark = XL_TICK_MARK.OUTSIDE
value_axis.tick_labels.font.italic = False
value_axis.tick_labels.font.size = Pt(12)
value_axis.tick_label_position = XL_TICK_LABEL_POSITION.LOW

plot to remove axis line

Upvotes: 0

Views: 1719

Answers (3)

FiftyBillion
FiftyBillion

Reputation: 1

If you want to hide the axis line but retain the tick-marks etc., it will be like this:

chart.value_axis.format.line.fill.background()
chart.category_axis.format.line.fill.background()

Upvotes: 0

Sander van den Oord
Sander van den Oord

Reputation: 12818

This doesn't remove the axis line, but makes it white, so it is also not visible anymore:

from pptx.dml.color import RGBColor

category_axis.format.line.color.rgb = RGBColor(255, 255, 255)

Upvotes: 0

scanny
scanny

Reputation: 28923

I believe this code will do what you're asking for:

chart.category_axis.visible = False
chart.value_axis.visible = False

If you want to hide the axis line but retain the tick-marks etc., try setting the width of the axis line to zero:

chart.category_axis.format.line.width = 0

Upvotes: 2

Related Questions