Issue
I have the following code:
from pandas_datareader import data as web
df = web.DataReader('goog','yahoo', start="2021-07-3", end="2021-09-12")
mpf.plot(df, style='charles', type = 'candle', volume=True, figratio=(12,8), title = "new title \n another title")
Could you please advise how can i change the font and size of newline another title
?
Solution
- As per How to edit the fig with the new mplfinance package, use
returnfig=True
to extract thefig
and a list ofaxes
objects. - Then use standard
matplotlib
methods to add anaxes title
and afigure suptitle
, becausetitle
inmpf.plot
is actually thefigure suptitle
, not theaxes title
. - References:
matplotlib.axes.Axes.set_title
matplotlib.pyplot.suptitle
matplotlib.text.Text
for text properties likestyle
df = web.DataReader('goog','yahoo', start="2021-07-3", end="2021-09-12")
fig, axlist = mpf.plot(df, style='charles', type = 'candle', volume=True, figratio=(12,8), returnfig=True)
# add a new suptitle
fig.suptitle('Figure Title', y=1.05, fontsize=30, x=0.59)
# add a title the the correct axes
axlist[0].set_title('Axis Title', fontsize=25, style='italic', fontfamily='fantasy', loc='center')
# save the figure
fig.savefig('test.jpg', bbox_inches='tight')
Answered By - Trenton McKinney
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.