我试图将辅助x轴添加到共享相同y轴的图表。我尝试将其中一个图形作为一条线,将另一图形作为散布线,然后使用Combine函数,但是我没有得到想要的东西。
这就是我所做的。
import xlsxwriter
worksheet = workbook.add_worksheet("Charts")
# I have some predetermine data in each sheet
id_sheet = worksheet1.name
td_sheet = worksheet2.name
gbin_sheet = worksheet3.name
# chart = workbook.add_chart(
# {'type': 'scatter', "subtype": "straight"})
# chart1 = workbook.add_chart(
# {'type': 'scatter', "subtype": "straight"})
chart = workbook.add_chart(
{'type': 'line'})
chart = workbook.add_chart(
{'type': 'line'})
# [sheetname, first_row, first_col, last_row, last_col]
chart.add_series({
'categories': [id_sheet, 1, 0, id_row_range, 0],
'values': [id_sheet, 1, 1, id_row_range, 1],
# 'name': "Signal_A",
})
chart.add_series({
'categories': [gbin_sheet, 1, 0, gbin_row_range, 0],
'values': [gbin_sheet, 1, 1, gbin_row_range, 1],
'name': "Signal_B",
'x2_axis': True,
# 'y2_axis': True,
})
chart.set_title({'name': 'Test results'})
chart.set_x_axis({'name': 'Cyclemarker'})
chart.set_y_axis({'name': 'Signal', 'major_gridlines': {
'visible': 0}, 'crossing': "max"})
chart.set_x2_axis({'name': 'time'})
# chart.set_y2_axis({'name': 'Signal', 'major_gridlines': {
# 'visible': 0}, 'crossing': 0})
# Insert the chart into the worksheet (with an offset).
worksheet.insert_chart('D2', chart, {'x_offset': 25, 'y_offset': 10})
workbook.close()
我得到两个图,顶部只有一个x轴。请帮忙。