Python Matplotlib point colour

一世执手 提交于 2019-12-22 06:48:22

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/15554939/python-matplotlib-point-colour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!