python画图颜色随机_Python Matplotlib点颜色

1586010002-jmsa.png

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!

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值