Matplotlib.colors.TwoSlopeNorm class in Python Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Matplotlib.colors.TwoSlopeNorm The matplotlib.colors.TwoSlopeNorm class is used to normalize data with the set center. It comes handy while mapping data with unequal rates of change around the conceptual center. For example, the range between -3 to 6 has a center 0. Syntax: class matplotlib.colors.TwoSlopeNorm(vcenter, vmin=None, vmax=None)Parameters: vcenter: It holds a float value that defines 0.5 in normalization. vmin: This is an optional parameter that defines the data value 0.0 in normalization. It defaults to minimum value of the dataset. vmax: This is an optional parameter that defines the data value 1.0 in normalization. It defaults to maximum value of the dataset. Method of the class: autoscale_none(self, A): This method is used to clip at vcenter by getting vmax and vmin. Example 1: Python3 import numpy as np import matplotlib.pyplot as plt import matplotlib.cbook as cbook import matplotlib.colors as colors file = cbook.get_sample_data('topobathy.npz', asfileobj = False) with np.load(file) as example: topo = example['topo'] longi = example['longitude'] latit = example['latitude'] figure, axes = plt.subplots(constrained_layout = True) # creating a colormap that has land # and ocean clearly delineated and # of the same length (256 + 256) undersea = plt.cm.terrain(np.linspace(0, 0.17, 256)) land = plt.cm.terrain(np.linspace(0.25, 1, 256)) every_colors = np.vstack((undersea, land)) terrain_map = colors.LinearSegmentedColormap.from_list('terrain_map', every_colors) # the center is offset so that # the land has more dynamic range # while making the norm diversity_norm = colors.TwoSlopeNorm(vmin =-500, vcenter = 0, vmax = 4000) pcm = axes.pcolormesh(longi, latit, topo, rasterized = True, norm = diversity_norm, cmap = terrain_map, ) axes.set_xlabel('Longitude $[^o E]$') axes.set_ylabel('Latitude $[^o N]$') axes.set_aspect(1 / np.cos(np.deg2rad(49))) figure.colorbar(pcm, shrink = 0.6, extend ='both', label ='Elevation [m]') plt.show() Output: Example 2: Python3 import numpy as np import matplotlib.pyplot as plt import matplotlib.colors as mcolors data = np.random.normal(.4, 2, (10, 10)) two_slope_norm = mcolors.TwoSlopeNorm(vmin = data.min(), vmax = data.max(), vcenter = 0) plt.imshow(data, cmap = plt.cm.RdBu, norm = two_slope_norm) plt.colorbar() plt.show() Output: Comment More infoAdvertise with us Next Article Must Coding Questions - Company-wise R rajukumar19 Follow Improve Article Tags : Python Write From Home Python-Library Python-matplotlib Practice Tags : python Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like