Matplotlib 将散点图的形状更改为曲线图图例中的直线

Matplotlib 将散点图的形状更改为曲线图图例中的直线,matplotlib,julia,legend,legend-properties,Matplotlib,Julia,Legend,Legend Properties,我正在尝试更改散点图的标签,以显示一条线而不是一个小点,因为这个点在屏幕上很难看到,更不用说在打印中了: PyPlot库是否允许这样做?我的代码的相关部分如下: println("Importing (and possibly compiling JIT) a few relevant libraries...") using LaTeXStrings,PyPlot; println("Calculating a few points...") samples = 10000; T = 2

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

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");

在python语法中,您可以通过
h,l=ax.get_legend\u handles\u labels()
获取图例句柄和标签,然后将最后一个替换为一行
newh=h[:-1]+[plt.Line2D([],[],color=“C0”)]
并在图例创建时提供它们,
ax.legend(handles=newh,labels=l)
。在此上下文中,什么是
plt
?您是否尝试将
plt.
退出?pyplot似乎位于全局命名空间中。