What python colors are available for use in matplotlib plots?
I’ve come across the following list of color names in the matplotlib documentation, which claims that these are the only valid named colors:
- b: blue
- g: green
- r: red
- c: cyan
- m: magenta
- y: yellow
- k: black
- w: white
However, I have found that I can also use other colors, such as:
- scatter(X,Y, color=‘red’)
- scatter(X,Y, color=‘orange’)
- scatter(X,Y, color=‘darkgreen’)
These colors don’t appear in the original list. Can anyone provide an exhaustive list of python colors available in matplotlib?
Hello @smrity.maharishsarin
Matplotlib offers a great feature: named colors! You can use its extensive list of named colors directly. For example, you can access these colors like this:
import matplotlib.colors as mcolors
print(mcolors.CSS4_COLORS)
This gives you a dictionary of over 140 named colors, ranging from simple ones like ‘red’ and ‘blue’ to more specific ones like ‘cornflowerblue’ and ‘darkgoldenrod.’ It’s a handy way to use predefined python colors without needing to know their RGB values!
Hey All!
Hope you all are doing Great!
That’s a solid starting point, @babitakumari ! Adding to your point, did you know that Matplotlib also supports XKCD colors? These come from the popular XKCD color survey and offer more than 950 unique color names. You can access them like this:*
import matplotlib.pyplot as plt
print(plt.colors.XKCD_COLORS)
This list includes quirky names like ‘vomit green’ or ‘cloudy blue’—great if you want a more informal or playful touch in your visualizations. It’s another excellent way to expand your palette of python colors!
Both named colors and XKCD colors are great resources! But if you want even more control, why not define your own colors? Matplotlib lets you use custom colors by specifying RGB or RGBA values directly. Here’s an example:
plt.scatter(X, Y, color=(0.5, 0.5, 0.5)) # This creates a gray scatter plot
You can create any color by mixing red, green, and blue (plus alpha for transparency). This gives you infinite possibilities, ensuring your visualizations are as unique as you want them to be!
I just wanted to add my 2 cents.
I completely agree with @babitakumarimcolors.CSS4_COLORS is a lifesaver. I use mediumslateblue and darkorange all the time for my plots because they really pop without being too harsh.
One tip from my experience: if you need precise brand colors, don’t rely on names—use hex codes or RGB tuples. For example, (0.2, 0.6, 0.8) gives me exactly the shade I want. I once had to redo a whole figure because I used a named color that looked slightly different on the projector
.
Also, I personally stick to colormaps like viridis for heatmaps, it’s colorblind-friendly and easy to interpret. Random named colors can look fun, but for serious data, they can confuse readers.
Hey @smrity.maharishsarin
I wanted to share a slightly different perspective. I love using XKCD colors! Some of them are hilariouspowder blue, ugly pink, cloudy purple, but they really make informal plots more fun. For casual dashboards or presentations to non-technical audiences, it actually helps keep people engaged.
That said, I have to disagree with relying solely on XKCD names for formal reports. I once tried using vomit green for a lab report… big mistake
.
In that case, CSS4 named colors or hex codes are definitely the safer option.
One thing I learned the hard way: always define your own color dictionary if you want consistency across multiple figures. It saves a lot of headaches.
Hey @smrity.maharishsarin
I mostly work with grayscale and RGB tuples.
Sometimes, you don’t want a colorful plot, and grayscale strings like '0.3' or '0.7' are perfect. I even mix them with alpha transparency (alpha=0.5) to layer multiple datasets; it looks clean and professional.
For heatmaps and continuous data, colormaps like plasma or cividis are my go-to. I think it’s worth noting that perceptually uniform colormaps prevent misinterpretation, unlike picking random colors.
And honestly, my favorite trick is defining a small palette dictionary like:
my_colors = {'primary':'#1f77b4', 'highlight':'#ff7f0e'}
Keeps everything neat, especially when I have to make 10+ plots for a report. From my experience, it’s a small step that makes your visualizations look professional and consistent.