Dance Party2
Dance Party2

Reputation: 7536

XLSX Writer Hide Axis Line Only

Given the chart below, I am looking for a way in XLSX-Writer to hide the bottom axis line without losing the categorical labels ([6,7,8,9]).

I have tried using major and minor grid lines, but no dice (though this did hide the tick marks, which was one of my goals):

chart.set_x_axis({'major_tick_mark': 'none',
                 'minor_gridlines':{'visible':False}})

Thanks in advance!

Need to Hide Bottom Line

Upvotes: 3

Views: 1555

Answers (1)

jmcnamara
jmcnamara

Reputation: 41644

You can turn off the axis line using the line property. You will also need to turn off the horizontal gridlines.

Here is an example that I think replicates what you are looking for:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart.xlsx')
worksheet = workbook.add_worksheet()

# Create a new Chart object.
chart = workbook.add_chart({'type': 'column'})

# Write some data to add to plot on the chart.
worksheet.write_column('A1', [6, 7, 8, 9])
worksheet.write_column('B1', [50, 70, 60, 80])

# Configure the charts. In simplest case we just add some data series.
chart.add_series({'categories': '=Sheet1!$A$1:$A$4', 
                  'values': '=Sheet1!$B$1:$B$4'})

# Turn off the X axis line.
chart.set_x_axis({'line': {'none': True}})

# Turn off the Y axis and horizontal gridlines.
chart.set_y_axis({'visible': False,
                  'major_gridlines': {'visible': False}})

# Turn off the chart legend.
chart.set_legend({'none': True})                  

# Insert the chart into the worksheet.
worksheet.insert_chart('B7', chart)

workbook.close()

Output:

enter image description here

Upvotes: 3

Related Questions