将全局标题添加到 Plots.jl 子图 [英] Adding global title to Plots.jl subplots

查看:11
本文介绍了将全局标题添加到 Plots.jl 子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Plots.jl 为一组子图添加一个全局标题.

I would like to add a global title to a group of subplots using Plots.jl.

理想情况下,我会这样做:

Ideally, I'd do something like:

using Plots
pyplot()
plot(rand(10,2), plot_title="Main title", title=["A" "B"], layout=2)

但是,根据 Plots.jl 文档plot_title属性尚未实现:

but, as per the Plots.jl documentation, the plot_title attribute is not yet implemented:

整个地块(不是子地块)的标题(注:当前未实现)

Title for the whole plot (not the subplots) (Note: Not currently implemented)

同时,有什么办法可以解决吗?

In the meanwhile, is there any way around it?

我目前正在使用 pyplot 后端,但我并不特别依赖它.

I'm currently using the pyplot backend, but I'm not especially tied to it.

推荐答案

当使用 pyplot 后端时,你可以使用 PyPlot 命令来改变一个 Plots 图,参见使用 Julia Plots 访问后端特定功能.

When using the pyplot backend, you can use PyPlot commands to alter a Plots figure, cf. Accessing backend specific functionality with Julia Plots.

要为整个图形设置标题,您可以执行以下操作:

To set a title for the whole figure, you could do something like:

using Plots
p1 = plot(sin, title = "sin")
p2 = plot(cos, title = "cos")
p = plot(p1, p2, top_margin=1cm)
import PyPlot
PyPlot.suptitle("Trigonometric functions")
PyPlot.savefig("suptile_test.png")

需要显式调用PyPlot.savefig来查看PyPlot函数的效果.

One needs to explicitly call PyPlot.savefig to see the effect of the PyPlot functions.

请注意,使用 PyPlot 接口所做的所有更改都会在您使用 Plots 函数时被覆盖.

Note that all changes made using the PyPlot interface will be overwritten when you use a Plots function.

这篇关于将全局标题添加到 Plots.jl 子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆