加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

在matplotlib python中制作hexbin填充方轴上的空白区域?

发布时间:2020-12-16 21:37:17 所属栏目:Python 来源:网络整理
导读:我正在尝试使用hexbin在方轴上绘制一些数据.我使用以下内容: import matplotlib.cm as cm plt.figure() num_pts = 1000 x = rand(num_pts) * 100 y = rand(num_pts) * 250 x_min = 0 x_max = 150 x_step = 25y_min = 50 y_max = 300 y_step = 50 s = plt.su
我正在尝试使用hexbin在方轴上绘制一些数据.我使用以下内容:
import matplotlib.cm as cm                              
plt.figure()  
num_pts = 1000             
x = rand(num_pts) * 100                                                                          
y = rand(num_pts) * 250              
x_min = 0               
x_max = 150                       
x_step = 25

y_min = 50           
y_max = 300                          
y_step = 50       

s = plt.subplot(1,1,1)                                                                                                                              
plt.hexbin(x,y,cmap=cm.jet,gridsize=20)             
plt.xticks(range(x_min,x_max+x_step,x_step))                                                                                                                           
plt.yticks(range(y_min,y_max+y_step,y_step))                                                                                                                           
# square axes                
s.axes.set_aspect(1/s.axes.get_data_ratio())

我希望轴是方形的,我想设置我自己的xticks / yticks和x-y限制.对于某些轴值,不会有数据,因此hexbin计算的计数应为零 – 我希望hexbin将其绘制为空白空间,而不是将其保留为“白色”/空白如果使用cm.jet色彩映射.

我现在得到的是这个.

如何使用其色彩图填充空白区域?谢谢.

解决方法

我相信答案是使用extent = keyword参数,如:
plt.hexbin(x,gridsize = 20,extent=[x_min,x_max,y_min,y_max])

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读