tim*_*tim 7 matplotlib julia plots.jl
Plots
虽然简单而且功能强大,但有时候我想更多地控制情节中的各个元素以微调它的外观.
是否可以直接更新后端的绘图对象?
例如,对于默认pyplot
后端,我试过了
using Plots
p = plot(sin)
p.o[:axes][1][:xaxis][:set_ticks_position]("top")
Run Code Online (Sandbox Code Playgroud)
但情节不会改变.p.o[:show]()
之后的电话也无济于事.
换句话说:有没有办法将PyPlot
界面用于最初创建的图Plots
?
编辑:
PyPlot
保存图形时,对象的更改将变为可见(也在gui中):
using Plots
using PyPlot
p = Plots.plot(sin, top_margin=1cm)
gui() # not needed when using the REPL
gca()[:xaxis][:set_ticks_position]("top")
PyPlot.savefig("test.png")
Run Code Online (Sandbox Code Playgroud)
在这里,我用过p.o[:axes][1] == gca()
.必须设置top_margin=1cm
因为绘图区域没有自动调整(对于我的实际微调,这没关系).
只要仅使用PyPlot
接口,这也适用于后续更新.例如,在以下命令之后,除了顶部的标签之外,绘图还将具有红色右边框:
gca()[:spines]["right"][:set_color]("red")
PyPlot.savefig("test.png")
Run Code Online (Sandbox Code Playgroud)
但是,当使用Plots
类似命令时plot!(xlabel="foo")
,所有先前所做的更改都将PyPlot
被覆盖(这并不令人惊讶).
剩下的问题是如何以交互方式更新gui而无需PyPlot.savefig
明确调用.
归档时间: |
|
查看次数: |
265 次 |
最近记录: |