小编tim*_*tim的帖子

使用Julia Plots访问后端特定功能

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明确调用.

matplotlib julia plots.jl

7
推荐指数
1
解决办法
265
查看次数

如何迭代除AbstractArray的最后一个索引之外的所有索引

在Julia中,迭代所有索引的推荐方法AbstractArray是使用eachindex,例如,

for i in eachindex(a)
    do_something(a[i], i)
end
Run Code Online (Sandbox Code Playgroud)

与此相反1:length(a),eachindex(a)支持具有非常规索引的数组,即不从中开始的索引1.此外,对于具有慢线性索引的阵列,它更有效.

如果我想跳过我可以使用的第一个索引Iterators.drop(eachindex(a), 1)(有更好的方法吗?)但是如何以通用方式跳过最后一个?

iteration julia

5
推荐指数
1
解决办法
312
查看次数

标签 统计

julia ×2

iteration ×1

matplotlib ×1

plots.jl ×1