I am currently struggling with changing the font of y axis title & the charts title itself.
I have tried to create a font setting & applying it to the titles - with no luck what so ever.
new_chart.y_axis.title = chart_dict['y_title']
ft = Font(name='Calibri',
size=11,
bold = False,
italic = False,
vertAlign = None,
underline = 'none',
strike = False,
color = 'FF000000')
new_chart.y_axis.title.font = ft
Is there any easy setting for this - like:
chart.y_axis.title.some_size_attrib = 12
or am I in the wrong direction?
I hope it won't get you too late. After a lot of research I was able to find a way to change the font and its size from a chart segment using Openpyxl.
The size of the font is defined at the sz=1500 and this means the usual 15 font size. Using that logic 1200 is 12. The minimum is 100 and the maximum is 400000.
from openpyxl.chart.text import RichText
from openpyxl.drawing.text import Paragraph, ParagraphProperties, CharacterProperties, Font
font_test = Font(typeface='Calibri')
cp = CharacterProperties(latin=font_test, sz=1500)
chart.x_axis.txPr = RichText(p=[Paragraph(pPr=ParagraphProperties(defRPr=cp), endParaRPr=cp)])
In my case that was not working properly. The one I used in the end was:
from openpyxl.drawing.text import CharacterProperties
cp = CharacterProperties(sz=1100) # Where size goes from 100 till 40000
mygraph.x_axis.title.tx.rich.p[0].r.rPr = cp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With