python坐标柱染色_Python matplotlib:在数据坐标中定位colorbar

本文展示了如何使用Python的matplotlib库在数据坐标而非图形坐标中定位colorbar。通过设置Axes.set_axes_locator和set_clip_box方法,可以在指定的轴数据坐标位置创建并调整colorbar的位置。
摘要由CSDN通过智能技术生成

指定轴的数据坐标位置的两个步骤:使用Axes.set_axes_locator()设置一个函数,该函数在图形坐标中返回Bbox对象。在

通过set_clip_box()方法设置轴中所有子对象的剪辑框:

以下是完整代码:import numpy as np

import matplotlib.pyplot as plt

#Generate some random data:

a = -2

b = 2

x = (b - a) * np.random.random(50) + a

y = (b - a) * np.random.random(50) + a

z = (b) * np.random.random(50)

#Do a scatter plot

fig = plt.figure()

hdl = plt.scatter(x,y,s=20,c=z,marker='o',vmin=0,vmax=2)

ax = plt.gca()

ax.set_xlim([-2,2])

ax.set_ylim([-2,2])

#Specifying figure coordinates works fine:

fig_coord = [0.2,0.8,0.25,0.05]

cbar_ax = fig.add_axes(fig_coord)

def get_ax_loc(cbar_ax, render):

from matplotlib.transforms import Bbox

tr = ax.transData + fig

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值