0

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

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96

3 Answers3

2

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
scanny
  • 26,423
  • 5
  • 54
  • 80
0

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)
Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96
  • One other thing that might be worth trying Sander is `axis.format.line.fill.background()`, which is theoretically at least "no color". This works in some other contexts, like the border around a shape if I remember correctly. – scanny Sep 17 '21 at 16:24
0

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()