[Python] Summary of how to specify the color of the figure

Color name

color [Data Science in Python: Names and Lists of Colors Specifiable in matplotlib] (https://pythondatascience.plavox.info/matplotlib/%E8%89%B2%E3%81%AE%E5%90%8D%E5%89%8D)

cmap [beiz note: A list of matplotlib cmap (colormap) parameters. ] (https://beiznotes.org/matplot-cmap-list/)

Color specification by RGB value + transparency A

--Specify by character string:'# ????????', RGBA order by 2 digits from the top. For transparency, the last two digits are 00. --Specified by tuple: (R, G, B, A), each value is 0-1. Transparency is 0.0

By the way, the state of being completely transparent and invisible is called "transparency 0%".

The list is below.

[Primary Color Dictionary] (https://www.colordic.org/) [Qiita @ konifar: ARGB color code transparency summary] (https://qiita.com/konifar/items/106731d8a35303606597)

reference: [Python by Examples: Transparent colors] (http://python.omics.wiki/plot/matplotlib/transparent)

Example:

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0.0, 15.0, 0.1)
y = np.sin(x)
plt.plot(y      , color='#ff4500'  ) # orangered
plt.plot(y - 1.0, color='#4169e1'  ) # royalblue
plt.plot(y - 2.0, color='#4169e199') #royalblue, transparency 60%
plt.plot(y - 3.0, color='#4169e133') #royalblue, transparency 20%
plt.plot(y - 4.0, color='#4169e100') #royalblue, transparency 0%So i can't see

image.png

Specify the imshow color discretely

from matplotlib import colors
cmap = colors.ListedColormap(['white', 'red'])
bounds=[0,5,10]
norm = colors.BoundaryNorm(bounds, cmap.N)
img = plt.imshow(zvals, interpolation='nearest',
                 cmap=cmap, norm=norm)
plt.colorbar(img, cmap=cmap, norm=norm, boundaries=bounds, ticks=[0, 5, 10])

https://stackoverflow.com/questions/9707676/defining-a-discrete-colormap-for-imshow-in-matplotlib

Specify colors discretely from one color map

For example, when drawing multiple line graphs.

cmap = plt.get_cmap("Blues")
for i in xrange(len(y)):
    plt.plot(x, y[i], c=cmap(float(i)/N))

Qiita @ Tatejimaru137: Align the colors of the Matplotlib graph with similar colors (color map)

Adjust color map criteria

Qiita @ aisha: [Python] Adjust color map standards

Recommended Posts

[Python] Summary of how to specify the color of the figure
[Python2.7] Summary of how to use unittest
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
Summary of how to import files in Python 3
Summary of how to use MNIST in Python
How to specify attributes with Mock of python
[Python] How to specify the window display position and size of matplotlib
How to get the number of digits in Python
[Python] How to specify the download location with youtube-dl
[Selenium] How to specify the relative path of chromedriver?
Summary of how to use pyenv-virtualenv
How to get the Python version
[Python] How to import the library
Summary of how to use csvkit
[Python] Summary of how to use split and join functions
How to determine the existence of a selenium element in Python
How to change the log level of Azure SDK for Python
How to check the version of Django
How to change the color of just the button pressed in Tkinter
[Python] How to get the first and last days of the month
How to check the memory size of a dictionary in Python
How to update the python version of Cloud Shell on GCP
[Beginner memo] How to specify the library reading path in Python
Summary of how to write AWS Lambda
[Question] How to use plot_surface of python
How to crop the lower right part of the image with Python OpenCV
[Introduction to Python] How to sort the contents of a list efficiently with list sort
Summary of how to set up major Python Lint (pep8, pylint, flake8)
How to use the C library in Python
How to specify the launch browser for JupyterLab 3.0.0
How to find the area of the Voronoi diagram
[Python] How to use two types of type ()
How to specify the NIC to scan with amazon-dash
Summary of the differences between PHP and Python
[Python] How to change the date format (display format)
[Python] Get / edit the scale label of the figure
Specify the Python executable to use with virtualenv
How to specify TLS version in python requests
[Algorithm x Python] How to use the list
How to erase the characters output by Python
How to get dictionary type elements of Python 2.7
How to get the files in the [Python] folder
[Python numpy] Dynamically specify the index of the array
Summary of studying Python to use AWS Lambda
How to install Python
How to install python
the zen of Python
Summary of Python arguments
How to pass the execution result of a shell command in a list in Python
Summary of how to read numerical data with python [CSV, NetCDF, Fortran binary]
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
[python] How to sort by the Nth Mth element of a multidimensional array
How to find the coefficient of the trendline that passes through the vertices in Python
Note: How to get the last day of the month with python (added the first day of the month)
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
Easy way to check the source of Python modules
python beginners tried to predict the number of criminals
[Python] How to remove duplicate values from the list
How to know the port number of the xinetd service