我不喜欢Gadfly在绘图时选择轴限制的方式,例如,我制作的一个绘图只在画布的中心四分之一有数据。MWE可以是:
plot(x=[2.9,8.01],y=[-0.01,0.81])

然后,Gadfly选择x轴范围0,10和-0.5,1作为y轴,这两个范围对我来说都太宽了。这里的值显然是虚构的,但基本上是我的真实数据的边界框。
我不希望有那么多空格,比如R的默认4%模式(即par(xaxs='r',yaxs='r'))。我可以通过执行以下操作在Gadfly中获得类似的结果:
plot(x=[2.9,8.01],y=[-0.01,0.81]
Guide.xticks(ticks=[3:8]),
Guide.yticks(ticks=[0:0.2:0.8]))即

这样的东西在Gadfly中已经存在了吗?考虑到我很难找到Guide.[xy]ticks,我希望我需要为这个…编写一些代码
感谢您的指点!
发布于 2015-03-10 06:17:07
作为一种变通方法,我有一个修改过的Heckbert's 1990's Graphics Gems code版本,它可以在给定的最小/最大值内生成刻度。在(我天真的)Julia中看起来是这样的:
# find a "nice" number approximately equal to x.
# round the number if round=true, take the ceiling if round=false
function nicenum{T<:FloatingPoint}(x::T, round::Bool)
ex::T = 10^floor(log10(x))
f::T = x/ex
convert(T, if round
if f < 1.5; 1.
elseif f < 3.; 2.
elseif f < 7.; 5.
else; 10.
end
else
if f <= 1.; 1.
elseif f <= 2.; 2.
elseif f <= 5.; 5.
else; 10.
end
end)*ex
end
function pretty_inner{T<:FloatingPoint}(min::T, max::T, ntick::Int)
if max < min
error("min must be less than max")
end
if min == max
return min:one(T):min
end
delta = nicenum((max-min)/(ntick-1),false)
gmin = ceil(min/delta)*delta
gmax = floor(max/delta)*delta
# shift max a bit in case of rounding errors
gmin:delta:(gmax+delta*eps(T))
end并且可以用作:
plot(x=[2.9,8.01],y=[-0.01,0.81],
Guide.xticks(ticks=[pretty_inner(2.9,8.01,7)]),
Guide.yticks(ticks=[pretty_inner(-0.01,0.81,7)]))并将得到与R相同的结果。
如果范围可以自动拉出就好了,但我不知道如何在现有的Gadfly代码中做到这一点。
https://stackoverflow.com/questions/28943866
复制相似问题