【发布时间】:2022-01-23 15:02:27
【问题描述】:
在my post earlier 的帮助下,我成功地将我的图表变成了烛台图表。但是我似乎无法调整它的大小。
我想将其调整为以前的大小。我尝试将以下内容添加到 rcparams 但没有效果:
"figure.figsize": figure_size,
"savefig.bbox": "tight"
我的旧相关代码:
figure = plt.Figure(figsize=(0.7 * res_width / 100, 0.45 * res_height / 100), facecolor=BACKGROUND_COLOUR)
ax = figure.add_subplot(111, fc=BACKGROUND_COLOUR)
figure.tight_layout()
figure.subplots_adjust(left=0.05, right=1.0, bottom=0.0, top=1.0)
FigureCanvasTkAgg(figure, self).get_tk_widget().place(relx=0.02, rely=0.27)
我当前的代码:
market_colours = mpf.make_marketcolors(up="g", down="r",
edge=background_colour,
wick=line_colour)
style_dict = {"xtick.color": line_colour,
"ytick.color": line_colour,
"xtick.labelcolor": text_colour,
"ytick.labelcolor": text_colour,
"axes.spines.top": False,
"axes.spines.right": False,
"axes.labelcolor": text_colour}
style = mpf.make_mpf_style(marketcolors=market_colours,
facecolor=background_colour,
edgecolor=line_colour,
figcolor=background_colour,
gridcolor=line_colour,
gridstyle="--",
rc=style_dict)
figure, ax = mpf.plot(df, type="candle", returnfig=True, style=style, TEXT_COLOUR))
FigureCanvasTkAgg(figure, self).get_tk_widget().place(relx=0.02, rely=0.27)
在小部件上尝试.pack(expand=True) 时,它也不起作用。
编辑:
感谢 Goldfarb 先生,我让图表变得更大,但它仍然不合适。有没有办法可以应用我通常添加的figure.tight_layout() 和figure.subplots_adjust(left=0.05, right=1.0, bottom=0.0, top=1.0)?
【问题讨论】:
-
尝试在最后一行使用包管理器而不是位置管理器,即
FigureCanvasTkAgg(figure, self).get_tk_widget().pack(expand = true),看看它是否有效(expand = true是可选的。它只是告诉小部件占用所有可用空间) .但是,请记住,这可能会导致您在使用不同的几何管理器时对定位小部件进行微小的更改。 -
@Grasshopper 这对图表的比例没有影响,请参阅我对帖子的编辑。
-
为了清楚起见(我对 Tkinter 不是很熟悉),关于 this image here 和 this other image here,这两个图像显示 三个 单独的 matplotlib 图形嵌入到 Tkinter 屏幕中? (问是因为我没有看到“Volume($)”图的代码,也没有看到“RSI(%)”图的代码。只是想确认我正确理解了我正在查看的内容。
标签: python matplotlib mplfinance