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

Changing the shape of a scatter plot to a line in a Julia PyPlot legend

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

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 对象的方法。

这是@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");