Fix Python – OpenCV giving wrong color to colored images on loading

I’m loading in a color image in Python OpenCV and plotting the same. However, the image I get has it’s colors all mixed up.
Here is the code:
import cv2
import numpy as np
from numpy import array, arange, uint8
from matplotlib import pyplot as plt

img = cv2.imread(‘lena_caption.png’, cv2.IMREAD_COLOR)
bw_img = cv2.cvtColor(img, cv2.COLOR_BGR2G….

Fix Python – matplotlib colorbar for scatter

I’m working with data that has the data has 3 plotting parameters: x,y,c. How do you create a custom color value for a scatter plot?
Extending this example I’m trying to do:
import matplotlib
import matplotlib.pyplot as plt
cm =‘RdYlBu’)
colors=[cm(1.*i/20) for i in range(20)]
xy = range(20)

Fix Python – Converting Hex to RGB value in Python

Working off Jeremy’s response here: Converting hex color to RGB and vice-versa I was able to get a python program to convert preset colour hex codes (example #B4FBB8), however from an end-user perspective we can’t ask people to edit code & run from there. How can one prompt the user to enter a hex value and then have it spit out a RGB value from t….

Fix Python – Getting individual colors from a color map in matplotlib

If you have a Colormap cmap, for example:
cmap =‘Spectral’)

How can you get a particular colour out of it between 0 and 1, where 0 is the first colour in the map and 1 is the last colour in the map?
Ideally, I would be able to get the middle colour in the map by doing:
>>> do_some_magic(cmap, 0.5) # Return an RGBA tuple

Fix Python – Named colors in matplotlib

What named colors are available in matplotlib for use in plots? I can find a list on the matplotlib documentation that claims that these are the only names:
b: blue
g: green
r: red
c: cyan
m: magenta
y: yellow
k: black
w: white

However, I’ve found that these colors can also be used, at least in this context:
scatter(X,Y, color=’red’)