将散点图的形状更改为Julia PyPlot图例中的线条

时间:2019-02-17 20:08:29

标签: matplotlib julia legend legend-properties

我正试图更改散点图的标签,以显示一条线而不是一个小点,因为该点很难在屏幕上看到,更不用说在打印中了:

Difficult to see dot.

PyPlot库允许这样做吗?我的代码的相关部分如下:

println("Importing (and possibly compiling JIT) a few relevant libraries...")
using LaTeXStrings,PyPlot;

println("Calculating a few points...")
samples = 10000;
T = 2 * pi;
x = collect(range(-pi,stop=pi,length=samples));
stepf = sign.(x);
N = 40;

"""
Sums of f
"""
fig, ax = subplots();
figname = "./Plots/filters.pdf";
ax[:scatter](x,stepf,label=latexstring("f(t)"),s=1);

ax[:axis]("off");
ax[:set_xlabel](latexstring("t"));
ax[:legend](loc="lower right");

fig[:savefig](figname);
close(fig)

编辑

基于以下评论,这将归结为寻找一种通过Julia来访问Matplotlib的Line2D对象的方法。

1 个答案:

答案 0 :(得分:1)

这是@ImportanceOfBeingErnest编写的代码,从Python转换为Julia PyCall。绝对有效!

h,l  = ax[:get_legend_handles_labels]()
z = PyPlot.plt[:Line2D]([],[], color="C0")
h[end] = z
ax[:legend](labels=l,  handles=h, loc="lower right");