如何在python中绘制hexbin图上的点?

2024-10-02 06:22:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个hexbin图,但是如何在这个图中添加其他点(例如两个点(x1,y1))???

谢谢

x=log(PR)
y=log(CR)

xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()

x1=log(np.array([10,20]))
y1=log(np.array([10,20]))
plt.hexbin(x1, y1, bins='log',color='red')
plt.hexbin(x, y, bins='log', cmap=plt.cm.gist_ncar)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("With a log color scale")
cb = plt.colorbar()
cb.set_label('log10(N)')
plt.show()

Tags: lognppltminarraymaxcolorxmin
1条回答
网友
1楼 · 发布于 2024-10-02 06:22:50

有几种方法,这取决于你想画什么。一些例子:

import matplotlib.pylab as pl
import numpy as np

x=np.random.random(1000)
y=np.random.random(1000)

pl.figure()
pl.hexbin(x, y, gridsize=5, cmap=pl.cm.PuBu_r)
pl.scatter(0.2, 0.2, s=400)
pl.text(0.5, 0.5, 'a simple text')
pl.text(0.6, 0.6, 'an aligned text', va='center', ha='center')
pl.annotate("an annotation for that scatter point", (0.2, 0.2), (0.3, 0.3),\
    arrowprops=dict(facecolor='black', shrink=0.05))

enter image description here

相关问题 更多 >

    热门问题