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

查看:50
本文介绍了向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.

请注意,使用 PlotPlot 函数时,使用 PyPlot 界面进行的所有更改都将被覆盖.

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

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

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