Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0890246

Browse filesBrowse files
committed
colorbar: allow more than one set of contour line marks
1 parent 413581c commit 0890246
Copy full SHA for 0890246

File tree

Expand file treeCollapse file tree

6 files changed

+20167
-22
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+20167
-22
lines changed

‎lib/matplotlib/colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.py
+17-8Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def __init__(self, ax, cmap=None,
255255
self.filled = filled
256256
self.extendfrac = extendfrac
257257
self.solids = None
258-
self.lines = None
258+
self.lines = list()
259259
self.outline = None
260260
self.patch = None
261261
self.dividers = None
@@ -467,14 +467,18 @@ def _add_solids(self, X, Y, C):
467467
)
468468
self.ax.add_collection(self.dividers)
469469

470-
def add_lines(self, levels, colors, linewidths):
470+
def add_lines(self, levels, colors, linewidths, erase=True):
471471
'''
472472
Draw lines on the colorbar.
473473
474474
*colors* and *linewidths* must be scalars or
475475
sequences the same length as *levels*.
476+
477+
Set *erase* to False to add lines without first
478+
removing any previously added lines.
476479
'''
477480
y = self._locate(levels)
481+
nlevs = len(levels)
478482
igood = (y < 1.001) & (y > -0.001)
479483
y = y[igood]
480484
if cbook.iterable(colors):
@@ -490,9 +494,10 @@ def add_lines(self, levels, colors, linewidths):
490494
xy = [zip(Y[i], X[i]) for i in xrange(N)]
491495
col = collections.LineCollection(xy, linewidths=linewidths)
492496

493-
if self.lines:
494-
self.lines.remove()
495-
self.lines = col
497+
if erase and self.lines:
498+
for lc in self.lines.pop():
499+
lc.remove()
500+
self.lines.append(col)
496501
col.set_color(colors)
497502
self.ax.add_collection(col)
498503

@@ -843,10 +848,13 @@ def on_mappable_changed(self, mappable):
843848
self.set_clim(mappable.get_clim())
844849
self.update_normal(mappable)
845850

846-
def add_lines(self, CS):
851+
def add_lines(self, CS, erase=True):
847852
'''
848853
Add the lines from a non-filled
849854
:class:`~matplotlib.contour.ContourSet` to the colorbar.
855+
856+
Set *erase* to False if these lines should be added to
857+
any pre-existing lines.
850858
'''
851859
if not isinstance(CS, contour.ContourSet) or CS.filled:
852860
raise ValueError('add_lines is only for a ContourSet of lines')
@@ -860,7 +868,8 @@ def add_lines(self, CS):
860868
#tcolors = [col.get_colors()[0] for col in CS.collections]
861869
#tlinewidths = [col.get_linewidth()[0] for lw in CS.collections]
862870
#print 'tlinewidths:', tlinewidths
863-
ColorbarBase.add_lines(self, CS.levels, tcolors, tlinewidths)
871+
ColorbarBase.add_lines(self, CS.levels, tcolors, tlinewidths,
872+
erase=erase)
864873

865874
def update_normal(self, mappable):
866875
'''
@@ -893,7 +902,7 @@ def update_bruteforce(self, mappable):
893902
self.outline = None
894903
self.patch = None
895904
self.solids = None
896-
self.lines = None
905+
self.lines = list()
897906
self.dividers = None
898907
self.set_alpha(mappable.get_alpha())
899908
self.cmap = mappable.cmap

‎lib/matplotlib/contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/contour.py
+5-7Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ def _initialize_x_y(self, z):
14941494
scaling data values to colors. If *norm* is *None* and
14951495
*colors* is *None*, the default linear scaling is used.
14961496
1497-
*vmin*/*vmax*: [ *None* | scalar ]
1497+
*vmin*, *vmax*: [ *None* | scalar ]
14981498
If not *None*, either or both of these values will be
14991499
supplied to the :class:`matplotlib.colors.Normalize`
15001500
instance, overriding the default color scaling based on
@@ -1561,18 +1561,16 @@ def _initialize_x_y(self, z):
15611561
linewidths in the order specified
15621562
15631563
*linestyles*: [ *None* | 'solid' | 'dashed' | 'dashdot' | 'dotted' ]
1564-
If *linestyles* is *None*, the 'solid' is used.
1564+
If *linestyles* is *None*, the default is 'solid' unless
1565+
the lines are monochrome. In that case, negative
1566+
contours will take their linestyle from the ``matplotlibrc``
1567+
``contour.negative_linestyle`` setting.
15651568
15661569
*linestyles* can also be an iterable of the above strings
15671570
specifying a set of linestyles to be used. If this
15681571
iterable is shorter than the number of contour levels
15691572
it will be repeated as necessary.
15701573
1571-
If contour is using a monochrome colormap and the contour
1572-
level is less than 0, then the linestyle specified
1573-
in ``contour.negative_linestyle`` in ``matplotlibrc``
1574-
will be used.
1575-
15761574
contourf-only keyword arguments:
15771575
15781576
*nchunk*: [ 0 | integer ]
Binary file not shown.
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.