问题描述
我只是从Julia开始,尝试使用 Gadfly 创建一个简单的sin/cos图.一切都很好,但是出于某些原因,Gadfly坚持将自己的Color... f1 f2
图例插入到绘图中(请参见图中的红色轮廓部分).谁能告诉我该如何删除它?我已经搜索过,但找不到任何东西.生成此代码的代码如下.
I'm just starting out with Julia and trying to create a simple sin/cos plot using Gadfly. It all works well, however for some reason Gadfly insists on inserting its own Color... f1 f2
legends into the plot (see the red-outlined portion in the image). Could anyone please tell me what I should do to remove it? I've searched but couldn't find anything. The code that generates this is given below.
我正在Windows 10上使用Julia 0.4.6.
I'm using Julia 0.4.6 on Windows 10.
using Gadfly
set_default_plot_size(9inch, 9inch/golden)
πs = Char(960) # pi in string form
ticklabel_data = ["$πs/2", πs, "3$πs/2", "2$πs", "5$πs/2"]
global c = 0
incr = () -> global c = (c + 1) % 5 == 0? 1 : (c + 1) % 5
ticklabels = () -> ticklabel_data[incr()]
plot([sin, cos],
0, 2 * pi,
Guide.xticks(ticks=[pi/2, pi, 3 * pi / 2, 2 * pi]),
Scale.x_continuous(labels = x -> @sprintf "%s" ticklabels()),
Guide.manual_color_key("Color", ["sin", "cos"], ["#D4CA3A", "deepskyblue"])
)
推荐答案
这似乎是因为您要绘制两件事情",而不是具有两层的一件事情".
This seems to be because you're plotting "two things", as opposed to "one thing" with two layers.
尝试:
plot(
layer(sin, 0, 2 * pi, Theme(default_color=colorant"#D4CA3A")),
layer(cos, 0, 2 * pi, Theme(default_color=colorant"deepskyblue")),
Guide.xticks(ticks=[pi/2, pi, 3 * pi / 2, 2 * pi]),
Scale.x_continuous(labels = x -> @sprintf "%s" ticklabels()),
Guide.manual_color_key("Color", ["sin", "cos"], ["#D4CA3A", "deepskyblue"])
)
这篇关于删除Gadfly图中自动生成的颜色键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!