Matplotlib 多个颜色条
我需要四个不同的颜色条来绘制单个图。我的图由 5 个子图组成,但只有第一个子图需要四个不同的颜色条形图。我想将它们放置在图表下方。我实现了它,但我的颜色条大小不同:
供您参考,我的图使用 matplotlib subplot2grid 方法分成 5 个图。一个最小的工作示例(没有 subplot2grid)如下所示:
import matplotlib.pyplot as plt
import numpy as np
frame = np.zeros([512, 512])
fig = plt.figure(figsize=(16, 8))
ax = plt.imshow(frame)
for i in range(4):
plt.colorbar(fraction=0.046, pad=0.04, location="bottom")
plt.show()
如何将颜色条形图放置在图下方,并且它们彼此相邻且长度相同(例如与第一个条形图的长度或图像大小相同)?
I need four different color bars for a single plot. My plot consists of 5 subplots, but only the first one requires four different color bar plots. I would like to position them below a graph. I achieved it, but my color bars are of different sizes:
For your reference, my figure is split into 5 figures using the matplotlib subplot2grid method. A minimal working example (without subplot2grid) is shown below:
import matplotlib.pyplot as plt
import numpy as np
frame = np.zeros([512, 512])
fig = plt.figure(figsize=(16, 8))
ax = plt.imshow(frame)
for i in range(4):
plt.colorbar(fraction=0.046, pad=0.04, location="bottom")
plt.show()
How do I position the color bar plots below the plot and them next to each other and of the same length (e.g. the same length as the first bar plot, or image size)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论