Пример (упрощенный) кода
Код: Выделить всё
# Import
from openpyxl import Workbook
from openpyxl.chart import LineChart, Reference
from openpyxl.chart.axis import ChartLines, TextAxis
from openpyxl.chart.shapes import GraphicalProperties
from openpyxl.drawing.colors import ColorChoice
# Create a line chart
chart = LineChart()
# Reference data from the worksheet I'm working with
num_rows = ws_data.max_row
num_cols = ws_data.max_column
data_ref = Reference(ws_data, min_col=2, min_row=1, max_col=num_cols, max_row=num_rows)
chart.add_data(data_ref, titles_from_data=True)
# Configure the x_axis
chart.x_axis = TextAxis(tickMarkSkip=4)
chart.x_axis.majorTickMark = "cross"
chart.x_axis.delete = False
# Configure the vertical gridlines
chart.x_axis.majorGridlines = ChartLines()
chart.x_axis.majorGridlines.graphicalProperties = GraphicalProperties(noFill=False, solidFill=ColorChoice(prstClr='yellow'))
# Add the chart to the 'Charts' worksheet
ws_chart.add_chart(chart, "A1")
Подробнее здесь: https://stackoverflow.com/questions/788 ... n-openpyxl