MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / add_lines

Method add_lines

lib/matplotlib/colorbar.py:753–831  ·  view source on GitHub ↗

Draw lines on the colorbar. The lines are appended to the list :attr:`!lines`. Parameters ---------- levels : array-like The positions of the lines. colors : :mpltype:`color` or list of :mpltype:`color` Either a single color

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

751 self._update_dividers()
752
753 def add_lines(self, *args, **kwargs):
754 """
755 Draw lines on the colorbar.
756
757 The lines are appended to the list :attr:`!lines`.
758
759 Parameters
760 ----------
761 levels : array-like
762 The positions of the lines.
763 colors : :mpltype:`color` or list of :mpltype:`color`
764 Either a single color applying to all lines or one color value for
765 each line.
766 linewidths : float or array-like
767 Either a single linewidth applying to all lines or one linewidth
768 for each line.
769 erase : bool, default: True
770 Whether to remove any previously added lines.
771
772 Notes
773 -----
774 Alternatively, this method can also be called with the signature
775 ``colorbar.add_lines(contour_set, erase=True)``, in which case
776 *levels*, *colors*, and *linewidths* are taken from *contour_set*.
777 """
778 params = _api.select_matching_signature(
779 [lambda self, CS, erase=True: locals(),
780 lambda self, levels, colors, linewidths, erase=True: locals()],
781 self, *args, **kwargs)
782 if "CS" in params:
783 self, cs, erase = params.values()
784 if not isinstance(cs, contour.ContourSet) or cs.filled:
785 raise ValueError("If a single artist is passed to add_lines, "
786 "it must be a ContourSet of lines")
787 # TODO: Make colorbar lines auto-follow changes in contour lines.
788 return self.add_lines(
789 cs.levels,
790 cs.to_rgba(cs.cvalues, cs.alpha),
791 cs.get_linewidths(),
792 erase=erase)
793 else:
794 self, levels, colors, linewidths, erase = params.values()
795
796 y = self._locate(levels)
797 rtol = (self._y[-1] - self._y[0]) * 1e-10
798 igood = (y < self._y[-1] + rtol) & (y > self._y[0] - rtol)
799 y = y[igood]
800 if np.iterable(colors):
801 colors = np.asarray(colors)[igood]
802 if np.iterable(linewidths):
803 linewidths = np.asarray(linewidths)[igood]
804 X, Y = np.meshgrid([0, 1], y)
805 if self.orientation == 'vertical':
806 xy = np.stack([X, Y], axis=-1)
807 else:
808 xy = np.stack([Y, X], axis=-1)
809 col = collections.LineCollection(xy, linewidths=linewidths,
810 colors=colors)

Callers 7

__init__Method · 0.95
update_normalMethod · 0.95
test_contour_colorbarFunction · 0.80
test_contour_addlinesFunction · 0.80
contourf_demo.pyFile · 0.80
contour_manual.pyFile · 0.80

Calls 11

_locateMethod · 0.95
valuesMethod · 0.80
get_linewidthsMethod · 0.80
maxMethod · 0.80
add_collectionMethod · 0.80
to_rgbaMethod · 0.45
removeMethod · 0.45
get_figureMethod · 0.45
transformMethod · 0.45
invertedMethod · 0.45
set_clip_pathMethod · 0.45

Tested by 3

test_contour_colorbarFunction · 0.64
test_contour_addlinesFunction · 0.64