How to change Font size of chart title ?

2,006 views
Skip to first unread message

GY

unread,
Nov 14, 2017, 1:23:49 AM11/14/17
to openpyxl-users
Hi, Experts
I need your help

I want to change the font size of chart title, x_axis title and y_axis tile.
I tried everthing I know but I could make it...
So Can your help me ?




### Python 3.6.3/ openpyxl 2.4.9
from datetime import date
from openpyxl import Workbook
from openpyxl.chart import (
LineChart,
Reference,
)
from openpyxl.chart.axis import DateAxis
 
wb = Workbook()
ws = wb.active
 
rows = [
['Date', 'Batch 1', 'Batch 2', 'Batch 3'],
[date(2015,9, 1), 40, 30, 25],
[date(2015,9, 2), 40, 25, 30],
[date(2015,9, 3), 50, 30, 45],
[date(2015,9, 4), 30, 25, 40],
[date(2015,9, 5), 25, 35, 30],
[date(2015,9, 6), 20, 40, 35],
]
 
for row in rows:
  ws.append(row)
 
c1 = LineChart()
c1.title = "Line Chart"
c1.style = 13
c1.y_axis.title = 'Size'
c1.x_axis.title = 'Test Number'
 
data = Reference(ws, min_col=2, min_row=1, max_col=4, max_row=7)
c1.add_data(data, titles_from_data=True)
 
# Style the lines
s1 = c1.series[0]
s1.marker.symbol = "triangle"
s1.marker.graphicalProperties.solidFill = "FF0000" # Marker filling
s1.marker.graphicalProperties.line.solidFill = "FF0000" # Marker outline
 
s1.graphicalProperties.line.noFill = True
 
s2 = c1.series[1]
s2.graphicalProperties.line.solidFill = "00AAAA"
s2.graphicalProperties.line.dashStyle = "sysDot"
s2.graphicalProperties.line.width = 100050 # width in EMUs
 
s2 = c1.series[2]
s2.smooth = True # Make the line smooth
ws.add_chart(c1, "A10")
wb.save("line.xlsx")

gec...@gmail.com

unread,
Dec 1, 2017, 12:09:12 AM12/1/17
to openpyxl-users
from openpyxl.drawing.text import CharacterProperties
c1.x_axis.title.tx.rich.p[0].r.rPr = CharacterProperties(sz=3500)

GY

unread,
Dec 1, 2017, 3:12:49 AM12/1/17
to openpyxl-users
Thank you gec*@gmail.com

You make me happy.....

thanks a lot....

2017년 12월 1일 금요일 오후 2시 9분 12초 UTC+9, gec...@gmail.com 님의 말:

Noji Ratzlaff

unread,
Feb 4, 2019, 6:01:43 PM2/4/19
to openpyxl-users
WOW...I have searched for several days now, and have tried MANY bad suggestions, and THIS is the only one that worked!!!

However, I'm using a PieChart() class, and so had to adjust it like this:

<code>pie_chart.title.tx.rich.p[0].r.rPr = CharacterProperties(sz=3500)</code>

because the PieChart() class doesn't contain the x_axis property.

THANKS!!! You make me happy too!
Noji Ratzlaff
Reply all
Reply to author
Forward
0 new messages