[Python] Adjusted the color map standard

Summary

problem

import numpy as np
import matplotlib.pyplot as plt

np.random.seed( 1 )
arr = np.random.uniform( -20.0, 100.0, (3,4) )
plt.imshow( arr, cmap='bwr' )
plt.colorbar()

image.png

Match 0 and white (reference point of color map) in the figure of

solution

Use of matplotlib.colors.DivergingNorm

matplotlib: matplotlib.colors.DivergingNorm

norm = mcolors.DivergingNorm( vcenter=0.0, vmin=-20.0, vmax=100.0 )
plt.imshow( arr, cmap='bwr', norm=norm )

image.png

symlog has matplotlib.colors.SymLogNorm

matplotlib: matplotlib.colors.SymLogNorm

norm = mcolors.SymLogNorm( linthresh=1.0, linscale=1.0, vmin=-100.0, vmax=100.0 )
plt.imshow( arr, cmap='bwr', norm=norm )

image.png

However, if vmin = -20.0, the white position shifts from 0 (note the color bar in the figure below):

image.png

→ If you are particular about vmin = -20.0, do you need to draw the array in two steps, + and-?

reference

stackoverflow: Defining the midpoint of a colormap in matplotlib

Recommended Posts

[Python] Adjusted the color map standard
[Python] Adjusting the color bar
Specify the color in the matplotlib 2D map
Let's summarize the Python coding standard PEP8 (1)
Let's summarize the Python coding standard PEP8 (2)
From Python 3.4, pip becomes the standard installer! ??
[Python] Get the main color from the screenshot
Introducing the color map extension library palettable
Open an Excel file in Python and color the map of Japan
[Python] Colored map plot at the city level
Compare the speed of Python append and map
Spread the Geographical Survey Map tiles in Python
Find the maximum Python
HoloViews may become the standard for Python visualization tools
Have python parse the json entered from the standard input
Ruby, Python and map
the zen of Python
Fill the background with a single color with OpenCV2 + Python
[Python] Summary of how to specify the color of the figure
[Python] Split the date
[ev3dev × Python] Color sensor
palettable color map list
[Python] About standard input
How to debug the Python standard library in Visual Studio
What you can do with the Python standard library statistics
(Python3) No. oO (Are you using the standard library?): 5 shaders
Read the VTK file and display the color map with jupyter.
[Python] Correct usage of map
python3 Measure the processing speed.
Towards the retirement of Python2
Python 3.4 or later standard pip
Download the file in Python
Find the difference in Python
[Python3] Standard input [Cheat sheet]
Python standard unittest usage notes
About the Python module venv
blender, python, spiral staircase, color
Python3 standard input (competition pro)
About the enumerate function (python)
Standard input / summary / python, ruby
Receiving standard input tips @ python
matplotlib gallery and color map
Transposed matrix in Python standard
[Python] Get the previous month
Blender 2.9, Python, hexadecimal color specification
[Python 2/3] Parse the format string
Call the API with python3.
About the features of Python
python standard virtual environment venv
[Python] Check the installed libraries
What is a python map?
I downloaded the python source
The Power of Pandas: Python
Find the maximum python (improved)
[Python] I wrote the route of the typhoon on the map using folium
Color extraction with Python + OpenCV solved the mystery of the green background
Create a color picker for the color wheel with Python + Qt (PySide)
Read the standard output of a subprocess line by line in Python
The story of making a standard driver for db with python.
python note: map -do the same for each element of the list
Python standard module that can be used on the command line