I am using imshow() to create pseudo-coloured maps of matrices of values (2d numpy arrays). Using clim argument one can set the range of values (below 1 and 6) to be represented within the colour scale (see below). This way for example all outliers (whether 7 or 7000000) will be yellow. This skews the perception of the image, as the reader doesn't know if this pixel is 6 or 700000.
Does anyone know of any way to colour all values outside of this range some other fixed colour of choice, for example, magenta?
Related
I have a bunch of (x,y) type points. Corresponding to these points there is an associated value (within a specific range). These values can be used to put color to them (using some color map).
If we now use these (x,y) and color we can have a pixelated image (with a color pixel at each x,y). Is there an easy way to fill the pixels between so that I get a sensible gradient of colors.
TLDR: How to fill pixels within a boundary when you know values at nearby pixels?
The thing which makes it difficult for me is I have much more pixels to fill than the number of already colored pixels.
Also can I control the gradient type (linear, quadratic etc.)
What is the easiest way to display an array with only very few different values as an image plot, e.g. with imshow from matplotlib.pyplot, assigning fixed colors to each of the values that show up in the array? For instance, if the array contained only the binary values 0 and 1, I would like to be able to draw all value-0-pixels in yellow and all value-1-pixels in green, say. Can this be achieved using a customised colormap or is it necessary to write a new array containing the appropriate rgb tuple for each original value?
I have a dataset which has a different range of the x coordinate at each y coordinate, without a specific rule or a fixed delta_x. E.g.
y=0 -> x is 40 values in range(20, 55)
y=1 -> x is 40 values in range(24, 49)
y=2 -> x is 40 values in range(23, 59)
...
Is there a way to get a checkerboard plot with such data using imshow?
I have tried changing the extent at each y value in a loop, but this just shifts each row to the last extent i set. In the plots below, the horizontal extent at the top should be [1410, 2190], and the horizontal extent at the bottom is [1453, 4970]. The red and white lines are a simple plot on top, and should follow the area shaded in red and yellow. See image here
I have tried using tricontourf (after Oliver W.'s suggestion here), which handles the dataset fine, the plot is accurate. You can also see how the horizontal extent changes. There are some artifacts in the image however. I'd like to use rectangles without interpolation, instead of interpolated triangles, if possible. See image here
I have tried appending the minimum and maximum values of all x at each y, and using those values for the horizontal extent, and it kinda works. See image here
It's still not accurate, and I'm not sure why. I can get a slightly better/more correct image by changing the values manually, first try. See image here
I'd be grateful for any comments or suggestions.
In my Python code I draw some points on a canvas. To each point there is an associated quantity f(P) where f is a function taking values between [0,f_{max}].
I would like to color the points such that the color corresponds to the value of f(P), and the mapping should be continuous.
The issue is colors in python are represented in RGB format in other words a function of 3 variables, so I am unsure how to approach this.
You could map from HSV (hue, saturation, value) to RGB, varying the hue according to your scalar value and setting saturation and value to constants.
import colorsys
def scalar_to_rgb(scalar):
return colorsys.hsv_to_rgb(scalar, 1, 1)
Scale the value to between 0 and 1 before passing it to the function. The colours wrap around, 1 will give the same result as 0. If this is an issue you could use only part of the range between 0 and 1.
I am trying to take pixels from an image and plot them ontop of a Blue Marble map. I have figured out how to project them on to the map. I have just not been able to figure out how to color each individual pixel when they are projected onto the map.
I have been using the plot() method, when I do them individually the terminal automatically kills my process because it has to plot ~65000 times. Is there another method I could use? Is there a way to use an array of pixel colors in any of these methods? Is this possible with PIL?
rgb is the color array with a 3-tuple ie. (14,0,0) etc. full_x and full_y are a 2 dimensional array where it is # of pixels x 5 different x,y points (to make the pixel shape on the blue marble image)
This is where I tried to do an array of colors:
for i in range(len(rgb)):
hexV = struct.pack('BBB',*rgb[i]).encode('hex')
hexA.append('#' + hexV)
m.plot(full_x, full_y, color=hexA)
I have also tried:
for i in range(len(rgb)):
hexV = struct.pack('BBB',*rgb[i]).encode('hex')
#hexA.append('#' + hexV)
hexA = '#' + hexV
m.plot(full_x[i], full_y[i], color=hexA[i])
This is where I tried to do each pixel individually and then the process was automatically killed.
Any help would be much appreciated. Thanks in advance.
For anyone who sees this and has the same problem:
Apparently all you have to use is scatter. In order to map pixels/any other points with multiple colors use scatter with an x array, y array and pixel color array.