【发布时间】:2021-09-10 11:25:08
【问题描述】:
我是 matplotlib 的新手。我正在努力在第一个 .plot 调用中自定义我的情节元素。例如,ylabel 有效,但 xlabel 无效。我希望我可以将 savefig 命令分开,以便我可以在第一个 .plot 调用和 savefig 之间添加/修改绘图元素调用(因为我在网上看到的所有示例似乎都是创建情节然后单独修改元素,即 fplt.xlabel("Blah")
行我注意到我在网上找到的很多绘图示例(用于折线图等)分别提供了所有 x 和 y 值,但我喜欢我使用的绘图技术,因为它自动使用高、低等来显示制作蜡烛。
那么为什么这段代码可以工作:
fplt.plot(
dft,
type="candle",
style='charles',
addplot=extraPlot2,
ylabel=stock,
# xlabel="Blah", <= removed as doesn't work
figratio=(10, 6), volume=True,
savefig=dict(
fname=folder2,
bbox_inches="tight"
)
)
但是这段代码没有(即使添加了哈希):
fplt.plot(
dft,
type="candle",
style='charles',
addplot=extraPlot2,
ylabel=stock,
# xlabel="Blah", <= removed as doesn't work
figratio=(10, 6), volume=True,
)
# fplt.xlabel("Blah") <= would like to do this if I can get savefig to work
# fplt.xticks(rotation=45) <= i'd also like to do stuff like this
fplt.savefig(folder2)
我已尝试将 fplt.plot 设为变量并以该变量为目标,但没有成功。 对任何糟糕的术语表示歉意,我对此很陌生。
编辑:在下面添加了导入以供参考。而且我意识到为什么 xlabel 现在不起作用了,因为我看到我正在导入它。
import datetime as dt
from matplotlib.pyplot import bar, xlabel
from numpy import False_, NaN
import pandas as pd
from pandas_datareader import data as pdr
import yfinance as yf
from tkinter import EXCEPTION, Tk
from tkinter.filedialog import askopenfilename
import os
from pandas import ExcelWriter
import mplfinance as fplt
from pathlib import Path
【问题讨论】:
-
如果您查看 mplfinance 的源代码,您可以在此处 github.com/matplotlib/mplfinance/blob/master/src/mplfinance/… 看到
plot函数的有效关键字参数列表。它看起来不像'xlabel'包含在其中,尽管ylabel包含在其中。您可能想提交一个 github 问题,询问该选项是否/为什么不可用 github.com/matplotlib/mplfinance/issues。 -
副本中的答案由 mplfinance 包创建者编写。
标签: python matplotlib mplfinance