Это, безусловно, возможно, если добавить вторую серию строк с маркерами и без линии, чтобы показать точки, в которых значения совпадают.
Вот пример:
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$1',
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$B$2:$B$7',
})
# 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$1',
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$C$2:$C$7',
})
# Add a series to represent the intersection points, with markers only.
line_chart.add_series({
'name': '=Sheet1!$D$1',
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$D$2:$D$7',
'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()
Выход:
Обратите внимание, что в этом примере название серии «Равно» скрыто из легенды. Я не знаю, нужно ли вам это, но я добавил это для полноты картины. Опустите его, если он вам не нужен.
person
jmcnamara
schedule
22.04.2015