I am using Julia 1.1.0 and want to do some plotting in it. I am using Plots and pyplot backend for that.
I have two data that I want to plot with the same line style and color, differing them by markers.
Here is an example:
using Plots
pyplot()
nf = 150;
freq = exp10.(range(2, stop=6.4, length=nf)); #logspace
foo1 = (freq*2 .- 3);
foo2 = (freq .- 10);
plot(freq, foo1, label="foo 1", line=(1, :black, :solid), xaxis=:log, yaxis=:log)
plot!(freq, foo2, label="foo 2", line=(1, :black, :solid), marker=(:circle, :black, 3, 0,5))
Run Code Online (Sandbox Code Playgroud)
The problem is that the line with the markers gets convoluted. I did not find an argument to put a marker every n-th point (is there one?)
Then I tried to generate a plot with line and no markers using the full data, then a plot with only markers (no lines) with a sampled data, as follows
plot(freq, foo1, label="foo 1", line=(1, :black, :solid), xaxis=:log, yaxis=:log)
plot!(freq, foo2, line=(1, :black, :solid))
r = 1:10:nf;
plot!(freq[r], foo2[r], line=(false), marker=(:circle, :black, 3, 0,5))
plot!(freq[1:1:2], foo2[1:1:2], label="foo2", line=(1, :black, :solid), marker=(:circle, :black, 3, 0,5))
Run Code Online (Sandbox Code Playgroud)
It has the looks that I want, but now the legends are messed up. How could I suppress labels y2 and y3 from the legend?
我重新阅读文档,发现该属性label的系列:
系列的标签,出现在图例中。如果为空,则不添加图例条目。
因此,无论是否使用,将标签设为空字符串都""可以解决问题。label=falselabel=nothing
plot(freq, foo1, label="foo 1", line=(1, :black, :solid), xaxis=:log, yaxis=:log)
plot!(freq, foo2, line=(1, :black, :solid), label="")
r = 1:10:nf;
plot!(freq[r], foo2[r], line=(false), marker=(:circle, :black, 3, 0,5), label="")
plot!(freq[[1,11]], foo2[[1,11]], label="foo 2", line=(1, :black, :solid), marker=(:circle, :black, 3, 0,5))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2751 次 |
| 最近记录: |