Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Matplotlib point colour

I have been looking at temperature plotting with sensors and wanted to find how I can either construct a contour/heat map or edit the colours of my points based on a cmap?

I have the following very basic plot:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from pylab import *

figure(figsize=(15, 8))
# use ginput to select markers for the sensors
matplotlib.pyplot.hot()

markers = [(269, 792, 0.65), (1661, 800, 0.5), (1017, 457, 0.8)]
x,y,t = zip(*markers)

img = mpimg.imread('floor.png')
imgplot = plt.imshow(img, cmap=cm.hot)
plot(x, y, 'h', c=t, ms=15)

colorbar()
show()

The 3rd value in markers should hopefully be a point colour. However when I am making the plot it's colouring each point in the same way using the first value in markers. Is it possible to set the cmap of the points so I can use hot and relate it to an actual temperature? The current points are plotting in a light purple/lilac colour which I presume is the default cmap. I see cmap doesn't seem to be a valid value for plot so I'm not sure where I would specify that.

The alternative solution I would really like to try and figure out would be to instead use contours or histogram2d to show the heat radius. Is that possible to plot over an image? I had a look at This example but I can't seem to be able to edit it correctly to use actual values instead of the random function. Does anyone have an alternative solution/example code they have used in the past that does what I am looking for? I'm getting a little confused with what documentation I have found.

Thanks!

like image 238
Ollie Avatar asked Nov 04 '22 01:11

Ollie


1 Answers

This is what the scatter plot is for:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from pylab import *

figure(figsize=(15, 8))
# use ginput to select markers for the sensors
matplotlib.pyplot.hot()

markers = [(269, 792, 0.65), (1661, 800, 0.5), (1017, 457, 0.8)]
x,y,t = zip(*markers)

img = mpimg.imread('floor.png')
imgplot = plt.imshow(img, cmap=cm.hot)
scatter(x, y, marker='h', c=t, s=150)

colorbar()
show()

Note that the arguments are different from plot and that the size scale differently. If you want to change the color of the points, you might wanna use the cmap argument of scatter

like image 126
David Zwicker Avatar answered Nov 15 '22 06:11

David Zwicker