Python Forum
How to change font size of chart title and axis title ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to change font size of chart title and axis title ?
#6
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!
Reply


Messages In This Thread
RE: How to change font size of chart title and axis title ? - by DrFunn1 - Mar-30-2018, 04:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 13 29,169 May-20-2025, 12:26 PM
Last Post: hanmen9527
Question [split] How to ask Smart Questions (thread title expansion) darkuser 4 1,715 Nov-11-2024, 01:27 PM
Last Post: deanhystad
  IndexError: index 31 is out of bounds for axis 0 with size 31 YL789 1 1,065 Sep-21-2024, 09:46 AM
Last Post: Gribouillis
  Python code for alignment and font size 1418 0 1,037 Jan-14-2024, 03:56 AM
Last Post: 1418
  IndexError: index 10 is out of bounds for axis 0 with size 10 Mehboob 11 11,382 Sep-14-2023, 06:54 AM
Last Post: Mehboob
  read active document name - other than from the window title ineuw 0 1,044 Sep-11-2023, 09:06 AM
Last Post: ineuw
  Change font in a list or tuple apffal 4 3,922 Jun-16-2023, 02:55 AM
Last Post: schriftartenio
  Problem with scraping the Title from a web page Wagner822 0 1,342 Jun-29-2022, 11:31 PM
Last Post: Wagner822
  Change Text Size in Console? ShakeyPakey 9 15,936 Dec-09-2021, 02:51 AM
Last Post: drvlwho
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 7,208 Sep-14-2021, 08:29 AM
Last Post: hobbyist

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020