Python Matplotlib点颜色 [英] Python Matplotlib point colour

查看:237
本文介绍了Python Matplotlib点颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用传感器查看温度绘图,想找到如何构建轮廓/热图或基于cmap编辑点的颜色的方法?

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()

标记中的第三个值应该是点色.但是,当我绘制图时,它使用标记中的第一个值以相同的方式为每个点着色.是否可以设置点的cmap,以便我可以使用热点并将其与实际温度相关联?当前点以浅紫色/淡紫色绘制,我认为这是默认的cmap.我看到cmap似乎不是有效的plot值,所以我不确定该在哪里指定.

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.

我真的想尝试找出的替代解决方案是改为使用轮廓或直方图2d来显示热半径.可以在图像上绘制吗? 我看了这个示例,但我似乎无法编辑正确地使用实际值而不是随机函数.是否有人有我过去寻找的替代解决方案/示例代码?我对找到的文档感到有些困惑.

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.

谢谢!

推荐答案

这就是 scatter用于:

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()

请注意,参数与plot不同,并且大小比例不同.如果要更改点的颜色,则可能要使用scatter

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

这篇关于Python Matplotlib点颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆