1

这是我用来用 mplfinance 绘制股票价格图表的代码,我希望该图表是对数缩放的。我怎样才能做到这一点?

import mplfinance as mpf

# Data reading and processing steps omitted

mpf.plot(data, type='line')
4

2 回答 2

2

这是我想出的解决方案:

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()
于 2020-11-10T01:45:59.457 回答
0

@JakeBoggs 工作,但文本格式是科学记数法。对于其他正在研究此问题的人,我建议使用 ScalarFormatter 将轴转换回来

import mplfinance as mpf
from matplotlib import pyplot as plt
from matplotlib.ticker import ScalarFormatter

# Data reading and processing steps omitted

fig, axlist = mpf.plot(data, type='line', returnfig=True)
ax = axlist[0]
ax.set_yscale("log")
ax.yaxis.set_major_formatter(ScalarFormatter())
ax.yaxis.set_minor_formatter(ScalarFormatter())
plt.show()

于 2021-01-06T01:53:11.010 回答