contour lines < 0 - dashed??


>Using matplotlib 0.74.
>The default linestyle for contour lines representing values less than
>zero should be dashed.
>I have used this in the past ( I guess prior to 0.74) but now the
>behavior is different.
>The default appears to be a greyscale color map - all solid lines.
>Looking at the code - line 768 of, the negative lines are
>dashed if Ncolors == 1.
>As far as I can tell, there is no way for this to be true. The code
>change to rectify this is trivial,
>but I may be missing something.

I made the change to which you refer, that is, adding the condition "Ncolors == 1" to the test for changing to dashed lines. My rationale is that the default is to color the lines with the default colormap, in which case the level information is in the colors, and making the negative values dashed just adds clutter. If the intent is to use simple black (or any other single color) lines, then one uses the kwarg "colors=('k',)" (for example), in which case Ncolors == 1, and the negative lines are dashed. This is illustrated in the attached script.

If you don't specify a colormap, the default is taken from your .matplotlibrc file if it exists, otherwise from the system default .matplotlibrc: specifically, the line

image.cmap : jet # gray | jet

The present system default is jet, not gray, so I presume it is your own .matplotlibrc file that is changing the default to gray.

Note that contour returns two arguments: a list of contour levels, and a corresponding list of LineCollections, which make it quite easy to change the line properties. If you want multicolored lines dashed for negative levels, you can do something like this:

levs, colls = contour(Z, cmap=hot())
for lev, coll in zip(levs, colls):
     if lev < 0:
         coll.set_linestyle((0, (6.,6.)),)

My inclination is to keep the default behavior rather simple, and let people customize as above. It is debatable whether the default even for single-color lines at negative levels should be dashed; I think a better design, more consistent with matlab and with the spirit of matplotlib, would be to leave this out.

We could also add support for a linestyles kwarg, similar to the linewidths kwarg that contour already accepts.

Eric (2.42 KB)