问题描述
这是我使用mplfinance绘制股价图表时所使用的代码,我希望该图表被对数缩放。我该怎么做?
import mplfinance as mpf
# Data reading and processing steps omitted
mpf.plot(data,type='line')
解决方法
这是我想出的解决方案:
import mplfinance as mpf
from matplotlib import pyplot as plt
# Data reading and processing steps omitted
fig,axlist = mpf.plot(data,type='line',returnfig=True)
ax = axlist[0]
ax.set_yscale('log')
plt.show()
,
@JakeBoggs 起作用了,但随后的文本格式是科学记数法。对于正在研究此问题的任何其他人,我建议使用 ScalarFormatter 将轴转换回来
import mplfinance as mpf
from matplotlib import pyplot as plt
from matplotlib.ticker import ScalarFormatter
# Data reading and processing steps omitted
fig,returnfig=True)
ax = axlist[0]
ax.set_yscale("log")
ax.yaxis.set_major_formatter(ScalarFormatter())
ax.yaxis.set_minor_formatter(ScalarFormatter())
plt.show()