组合图表中的 xlsxwriter 标记

xlsxwriter Marker in Combined Chart

我正在尝试将标记添加到我在 xlsxwriter 中为 Python 创建的组合图表。在组合折线图和柱形图后,我想在 Val_1 = Val_2 的点上放置一个圆形标记。我不知道如何在 xlsxwriter 中执行此操作。我可以在 Excel 中完成,但是:

数据:

 Date   Val_1   Val_2   Flag
 1-Jan  100      50     #N/A
 2-Jan  150      250    #N/A
 3-Jan  125      100    #N/A
 4-Jan  110      110    110
 5-Jan  170      225    #N/A

After 我结合了我尝试的图表和“.add_series”,但我的图表不显示任何标记。我觉得这与组合图表有关。谁能举例说明如何做到这一点?

谢谢

这当然可以通过添加带有标记的第二行系列来显示值匹配的点。

这是一个例子:

from xlsxwriter.workbook import Workbook

workbook  = Workbook('chart_combined.xlsx')
worksheet = workbook.add_worksheet()

# Add a format for the headings.
bold = workbook.add_format({'bold': True})

# Add the worksheet data that the charts will refer to.
headings = ['Number', 'Batch 1', 'Batch 2', 'Equal']
data = [
    [2,        3,      4,        5,          6,    7      ],
    [10,       40,     50,       20,        10,    50     ],
    [30,       40,     70,       50,        10,    30     ],
    ['=NA()',  40,     '=NA()',  '=NA()',   10,    '=NA()'],
]

worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
worksheet.write_column('C2', data[2])
worksheet.write_column('D2', data[3])

# Create a new column chart. This will use this as the primary chart.
column_chart = workbook.add_chart({'type': 'column'})

# Configure the data series for the primary chart.
column_chart.add_series({
    'name':       '=Sheet1!$B',
    'categories': '=Sheet1!$A:$A',
    'values':     '=Sheet1!$B:$B',
})

# Create a new line chart. This will use this as the secondary chart.
line_chart = workbook.add_chart({'type': 'line'})

# Configure the data series for the secondary chart.
line_chart.add_series({
    'name':       '=Sheet1!$C',
    'categories': '=Sheet1!$A:$A',
    'values':     '=Sheet1!$C:$C',
})

# Add a series to represent the intersection points, with markers only.
line_chart.add_series({
    'name':       '=Sheet1!$D',
    'categories': '=Sheet1!$A:$A',
    'values':     '=Sheet1!$D:$D',
    'marker':     {'type': 'circle', 'size': 10},
    'line':       {'none': True},
})

# Delete/hide series 2 from the legend.
column_chart.set_legend({'delete_series': [2]})

# Combine the charts.
column_chart.combine(line_chart)

# Add a chart title and some axis labels. Note, this is done via the
# primary chart.
column_chart.set_title({ 'name': 'Combined chart'})
column_chart.set_x_axis({'name': 'Test number'})
column_chart.set_y_axis({'name': 'Sample length (mm)'})

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

workbook.close()

输出:

请注意,此示例隐藏了图例中的 "Equal" 系列名称。我不知道你是否需要它,但为了完整性我添加了它。不需要的请忽略。