【发布时间】:2014-09-09 22:37:53
【问题描述】:
正如问题所说,我有一个等高线图,我想为 if 显示一个图例。
我正在使用等高线绘图样式:
虚线表示负水平
实线表示正值
我想给他们一个图例(虚线 == 负数,实线 == 正数)。
我尝试了找到here 和here 的方法。但是,如下所示,这并没有显示正确的结果。
# Draw the scalar field level curves
div_field = plt.contour(x, y, div_scalar_field, colors='white')
rot_field = plt.contour(x, y, rot_scalar_field, colors='lightgoldenrodyellow')
labels = ['Div Neg', 'Div Pos', 'Rot Neg', 'Rot Pos']
div_field.collections[0].set_label(labels[0])
div_field.collections[-1].set_label(labels[1])
rot_field.collections[0].set_label(labels[2])
rot_field.collections[-1].set_label(labels[3])
对于 div 标量 字段,我只有正水平,所以我得到了两个具有相同线条样式的标签。
我想知道我怎样才能正确地实现我想要的。
提前谢谢你。
【问题讨论】:
标签: python matplotlib plot legend contour