Mar-30-2018, 04:02 PM
There are two methods to style chart text elements. Axis numbers can be styled using chart.text RichText properties and chart titles using drawing.text ParagraphProperties. The legend can be styled using either method.
from openpyxl.chart import ScatterChart, Reference, Series from openpyxl.chart.text import RichText from openpyxl.drawing.text import Paragraph, ParagraphProperties, CharacterProperties, RichTextProperties, Font, RegularTextRun # Set up basic XY Scatter Chart chart = ScatterChart() chart.title = "Scatter Chart" chart.style = 2 # Excel menu chart tools: Design > Chart Styles chart.x_axis.title = 'X-axis Title' chart.y_axis.title = 'Primary Y-axis Title' # Style chart # X and Y axes numbers font = Font(typeface='Verdana') size = 1400 # 14 point size cp = CharacterProperties(latin=font, sz=size, b=False) # Not bold pp = ParagraphProperties(defRPr=cp) rtp = RichText(p=[Paragraph(pPr=pp, endParaRPr=cp)]) chart.x_axis.txPr = rtp # Works! chart.y_axis.txPr = rtp # Works! # X and Y axes titles chart.x_axis.title.tx.rich.p[0].pPr = pp # Works! chart.y_axis.title.tx.rich.p[0].pPr = pp # Works!