How can I set the dash length in a matplotlib contour plot
Almost.
It's:
for c in CS.collections:
c.set_dashes([(0, (2.0, 2.0))])
If you had put a print c.get_dashes()
there, you would have found out (it's what I did).
Perhaps the definition of the line style has changed a bit, and you were working from an older example.
The collections documentation has this to say:
set_dashes(ls)
alias for set_linestyle
set_linestyle(ls)
Set the linestyle(s) for the collection.
ACCEPTS: [‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ | (offset, on-off-dash-seq) ]
So in [(0, (2.0, 2.0))]
, 0 is the offset, and then the tuple is the on-off repeating pattern.