Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用后图例格式丢失:ax.Legend(句柄、标签)_Python_Matplotlib_Label_Legend_Handle - Fatal编程技术网

Python 使用后图例格式丢失:ax.Legend(句柄、标签)

Python 使用后图例格式丢失:ax.Legend(句柄、标签),python,matplotlib,label,legend,handle,Python,Matplotlib,Label,Legend,Handle,我遇到了与本文相同的问题:用户希望删除图例中的重复条目: 答案也适用于我,但是,当我使用它时,图例格式完全丢失。当我应用ax.legend(句柄、标签)方法时会发生这种情况。以下代码(从中复制)说明了此问题: # Example data a = np.arange(0,3, .02) b = np.arange(0,3, .02) c = np.exp(a) d = c[::-1] # Create plots with pre-defined labels. # Alternativel

我遇到了与本文相同的问题:用户希望删除图例中的重复条目:

答案也适用于我,但是,当我使用它时,图例格式完全丢失。当我应用ax.legend(句柄、标签)方法时会发生这种情况。以下代码(从中复制)说明了此问题:

# Example data
a = np.arange(0,3, .02)
b = np.arange(0,3, .02)
c = np.exp(a)
d = c[::-1]

# Create plots with pre-defined labels.
# Alternatively, you can pass labels explicitly when calling `legend`.
fig, ax = plt.subplots()
ax.plot(a, c, 'k--', label='Model length')
ax.plot(a, d, 'k:', label='Data length')
ax.plot(a, c+d, 'k', label='Total message length')

# Now add the legend with some customizations.
legend = ax.legend(loc='upper center', shadow=True)

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels )   

# The frame is matplotlib.patches.Rectangle instance surrounding the legend.
frame = legend.get_frame()
frame.set_facecolor('0.90')

# Set the fontsize
for label in legend.get_texts():
    label.set_fontsize('large')

for label in legend.get_lines():
    label.set_linewidth(1.5)  # the legend line width
plt.show()
不使用“ax.legend(句柄、标签)”的结果:

使用“ax.legend(句柄、标签)”的结果:

任何建议都将受到欢迎


编辑1:更正输入错误'without'

您已经发出了两次调用
legend()
的命令,第二次调用时没有格式化参数,请替换:

legend = ax.legend(loc='upper center', shadow=True)

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels )


应该这样做。

您已经发出了两次
legend()
调用,第二次调用时没有格式化参数,请替换:

legend = ax.legend(loc='upper center', shadow=True)

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels )


应该这样做。

您已经发出了两次
legend()
调用,第二次调用时没有格式化参数,请替换:

legend = ax.legend(loc='upper center', shadow=True)

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels )


应该这样做。

您已经发出了两次
legend()
调用,第二次调用时没有格式化参数,请替换:

legend = ax.legend(loc='upper center', shadow=True)

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels )


应该这样做。

你的两张图片都说“没有”。哪一张是?拼写错误更正:谢谢帕特里克你的两张图片都说“没有”。哪一张是?拼写错误更正:谢谢帕特里克你的两张图片都说“没有”。哪一张是?拼写错误更正:谢谢帕特里克你的两张图片都说“没有”哪一个?错别字更正:谢谢你,帕特里克