python colorbar位置大小调整_python - matplotlib相邻子图:添加colorbar更改子图的大小 - 堆栈内存溢出...
实际上,以下来自用户ImportanceOfBeingErnest的注释并使用axes_grid1,我可以使它工作。
主要区别:对于每一行,我定义一个ImageGrid对象:
axrows = [[] for r in range(nrows)]
i = 0
for r in range(nrows):
axcols = [None for c in range(ncols)]
axcols = ImageGrid(fig, (nrows, 1, r+1),
nrows_ncols=(1, ncols),
axes_pad = 0.0,
share_all = True,
label_mode = 'L',
cbar_mode = 'edge',
cbar_location = 'right',
cbar_size = "7%",
cbar_pad = "2%")
axrows[r] = axcols
然后,在代码中的正确位置,我添加了颜色条
axcols.cbar_axes[0].colorbar(im)
这是完整的代码:
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors
from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size
from mpl_toolkits.axes_grid1 import ImageGrid
# border limits for plots
lowlim = 0.43
uplim = 0.52
nx = 10
kernels = ['cubic_spline', 'quintic_spline',
'wendland_C2', 'wendland_C4', 'wendland_C6']
#========================
def main():
#========================
eta_facts = [ 0, 1, 2, 3, 4, 5 ]
nrows = len(eta_facts)
ncols = len(kernels)
Ay_list = [[None for c in range(ncols)] for r in range(nrows)]
#--------------------------------
# Loop and compute As
#--------------------------------
dx = (uplim - lowlim)/nx
for row, eta in enumerate(eta_facts):
for col, kernel in enumerate(kernels):
A = np.zeros((nx, nx), dtype=np.float)
for i in range(nx):
for j in range(nx):
A[j,i] = row + np.random.random()/10 # not a typo: need A[j,i] for imshow
Ay_list[row][col] = A
#------------------------------------
# Now plot it
#------------------------------------
fig = plt.figure(figsize=(3.5*ncols+1, 3.5*nrows))
axrows = [[] for r in range(nrows)]
i = 0
for r in range(nrows):
axcols = [None for c in range(ncols)]
axcols = ImageGrid(fig, (nrows, 1, r+1),
nrows_ncols=(1, ncols),
axes_pad = 0.0,
share_all = True,
label_mode = 'L',
cbar_mode = 'edge',
cbar_location = 'right',
cbar_size = "7%",
cbar_pad = "2%")
axrows[r] = axcols
cmap = 'YlGnBu_r'
lw = 2
for row in range(nrows):
axcols = axrows[row]
minval = min([np.min(Ay_list[row][c]) for c in range(ncols)])
maxval = max([np.max(Ay_list[row][c]) for c in range(ncols)])
for col, ax in enumerate(axcols):
im = ax.imshow(Ay_list[row][col], origin='lower',
vmin=minval, vmax=maxval, cmap=cmap,
extent=(lowlim, uplim, lowlim, uplim),
# norm=matplotlib.colors.SymLogNorm(1e-3),
zorder=1)
ax.set_xlim((lowlim,uplim))
ax.set_ylim((lowlim,uplim))
# cosmetics
if col > 0:
left = False
else:
left = True
if row == len(eta_facts)-1 :
bottom = True
else:
bottom = False
ax.tick_params(
axis='both', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom=bottom, # ticks along the bottom edge are off
top=False, # ticks along the top edge are off
left=left, # ticks along the left edge are off
right=False, # ticks along the rigt edge are off
labelbottom=bottom, # labels along the bottom edge are off
labeltop=False, # labels along the top edge are off
labelleft=left, # labels along the left edge are off
labelright=False) # labels along the right edge are off
if row==0:
ax.set_title(kernels[col] + ' kernel', fontsize=14)
if col==0:
ax.set_ylabel(r"$\eta = $ "+str(eta_facts[row])+r"$\eta_0$")
axcols.cbar_axes[0].colorbar(im)
fig.suptitle(r"Some title", fontsize=18)
plt.tight_layout(rect=(0, 0, 1, 0.97))
plt.subplots_adjust(wspace=0.0, hspace=0.0)
plt.savefig('for_stackexchange.png', dpi=150)
plt.close()
print('finished.')
return
if __name__ == '__main__':
main()
哪个产生这个图像:
python colorbar位置大小调整_python - matplotlib相邻子图:添加colorbar更改子图的大小 - 堆栈内存溢出...相关推荐
- python 等值线 标注 间距、控制_python - Matplotlib-Contourf-如何使刻度线间距不均匀? - 堆栈内存溢出...
根据yticks上的matplotlib文档,您可以指定要使用的标签. 在您的情况下,如果要显示标签[10,100,500,1000,1500,2000,3000,4000,5000] ,则可以将该列 ...
- python求小于n的所有素数_python - 列出N以下所有素数的最快方法 - 堆栈内存溢出...
警告:由于硬件或Python版本的不同, timeit结果可能会有所不同. 下面是一个脚本,比较了许多实现: 非常感谢斯蒂芬为使sieve_wheel_30引起我的注意. 值得罗伯特·威廉·汉克斯 ( ...
- python拆堆和堆叠的操作_python - 如何合并不同的DFS并堆叠值? - 堆栈内存溢出
我有一个dict ,其中有17 df . 样本dfs : df1 key percent 0 step19_without_lof 14.534883720930232 df2 key percent ...
- python可视化添加文本_python Matplotlib基础--如何添加文本和标注
创建一个优秀的可视化图表的关键在于引导读者,让他们能理解图表所讲述的故事.在一些情况下,这个故事可以通过纯图像的方式表达,不需要额外添加文字,但是在另外一些情况中,图表需要文字的提示和标签才能将故事讲 ...
- Matplotlib:给子图添加colorbar(颜色条或渐变色条)
描述 当我们给图配渐变色时,常常需要在图旁边把colorbar显示出来,这里记一下当有多个子图时如何显示colorbar 操作 以下操作均在Jupyter notebook中完成,且首段均有以下代码 ...
- c与python内存传递_python - 从Python向C ++传递COM指针数组 - 堆栈内存溢出
我已经阅读了许多文档,示例和StackOverflow主题,但仍然无法正常工作! 我正在为我的C ++ COM对象编写一个Python接口. 这不是我第一次这样做. 过去,我已经成功地使用comtyp ...
- python画图颜色表示大小变化_Python matplotlib减少色条标签的大小
我需要你的帮助!我有一个绘图代码,它是以下: fig = plt.figure() ax1 = fig.add_subplot(111) imax1 = ax1.imshow(data,interpo ...
- python colorbar 0变白色_Python matplotlib更改超过colorbar范围的值的默认颜色
可以使用色彩映射的set_over和set_under方法设置超出范围的颜色;请参阅 the documentation.创建色彩映射时,需要指定这些值.虽然我没有看到任何matplotlibrc设置 ...
- python中axes什么意思_python matplotlib中axes与axis的区别是什么?
1.axes subplot axis 先说第一个疑惑 Axes - Subplot - Axis 之间到底是个什么关系? 因为我是努力在看英文的教程,所以刚开始对axes和axis是基本搞不清的,一 ...
最新文章
- 数据结构—顺序表的插入算法
- libsvm学习(二)——第一次体验libsvm(转)
- 关于客户端用ASP参生报表
- 复旦大学邱锡鹏教授:词法、句法分析研究进展综述
- 如何利用循环代替递归以防止栈溢出(译)
- bash參考手冊之六(Bash特性)
- 利用集合对数据进行去重操作
- VS 错误: 未找到与约束contractname Microsoft.VisualStudio.Utilities.IContentTypeRegistryService...
- 编写批处理文件编译.Net工程
- mysql中值换行显示为乱码_MySQL数据移植中的乱码问题
- 修改sublime 侧边栏 颜色 等
- 【精华】Asp优化之缓存技术
- Null + Anything = null, 好奇怪的设定啊
- [COCI2009]Dvapravca
- 浅谈算法和数据结构: 六 符号表及其基本实现
- 696.计数二进制子串(力扣leetcode) 博主可答疑该问题
- linux 蓝牙测试程序下载,Linux下蓝牙测试软件包和命令介绍
- java 类方法中this_Java Eclipse 中 在类与方法调用中 (this)的用法
- [ProblemSolving]教育网下载速度慢,如何解决?
- java 量化指标_SAR指标配合阶段高低价的量化交易策略