Skip to main content
 首页 » 编程设计

python之XLSX Writer 仅隐藏轴线

2024年09月07日7txw1958

鉴于下面的图表,我正在 XLSX-Writer 中寻找一种方法来隐藏底部轴线而不丢失分类标签 ([6,7,8,9])。

我尝试过使用主要和次要网格线,但没有骰子(尽管这确实隐藏了刻度线,这是我的目标之一):

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

提前致谢!

请您参考如下方法:

您可以使用 line 属性关闭轴线。您还需要关闭水平网格线。

这是一个我认为可以复制您正在寻找的内容的示例:

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

输出: