- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想生成一个带有颜色条的等高线图/热图,然后添加一个注释框。这个数字很丑,但得到了我想要的:
add_subplot()
是不够的。如果我尝试将所有内容都放在同一个子图中,则该框会被遮盖。我可以通过使其可拖动然后调整图像的大小来解决这个问题,但这并不好。我将不得不制作一些这样的图像,所有这些图像都是标准尺寸的,我不能一次又一次地与尺寸抗争。
我也尝试了 axes()
,将盒子放在一个单独的轴上。但这会生成一个新的绘图窗口,覆盖了我的大部分颜色条。我想会有办法让窗口完全透明。但是到了那个地步,我想我的做法一定是完全错误的。
这似乎不应该那么难。有什么想法吗?
最佳答案
这样做:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
from numpy.random import randn
from mpl_toolkits.axes_grid1.axes_divider import HBoxDivider
import mpl_toolkits.axes_grid1.axes_size as Size
def make_heights_equal(fig, rect, ax1, ax2, ax3, pad):
# pad in inches
h1, v1 = Size.AxesX(ax1), Size.AxesY(ax1)
h2, v2 = Size.AxesX(ax2, 0.1), Size.AxesY(ax2)
h3, v3 = Size.AxesX(ax3), Size.AxesY(ax3)
pad_v = Size.Scaled(1)
pad_h = Size.Fixed(pad)
my_divider = HBoxDivider(fig, rect,
horizontal=[h1, pad_h, h2, pad_h, h3],
vertical=[v1, pad_v, v2, pad_v, v3])
ax1.set_axes_locator(my_divider.new_locator(0))
ax2.set_axes_locator(my_divider.new_locator(2))
ax3.set_axes_locator(my_divider.new_locator(4))
# Make plot with vertical (default) colorbar
fig = plt.figure()
img_ax = fig.add_subplot(131)
bar_ax = fig.add_subplot(132)
ann_ax = fig.add_subplot(133)
data = np.clip(randn(250, 250), -1, 1)
im = img_ax.imshow(data, interpolation='nearest', cmap=cm.coolwarm)
# Add colorbar, make sure to specify tick locations to match desired ticklabels
cbar = fig.colorbar(im, cax=bar_ax, ticks=[-1, 0, 1])
cbar.ax.set_yticklabels(['< -1', '0', '> 1'])# vertically oriented colorbar
ann_ax.axis('off')
ann_ax.annotate("Hello, I'm an annotation", (0.5, 0.5),
xycoords="axes fraction", va="center", ha="center",
bbox=dict(boxstyle="round, pad=1", fc="w"))
make_heights_equal(fig, 111, img_ax, bar_ax, ann_ax, 0.2)
plt.savefig("try.png")
关于python - 将注释框添加到 matplotlib 等高线/热图图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17072716/
我试图理解 findContours 的输出基于 this one 等教程和文档。我想知道为什么我得到我得到的输出。我有一个中间有一个正方形的 jpeg img,我的目标是找到正方形并为其着色(只是为
我有一组数据,其中包含 x 和 y 坐标以及每个坐标的计算值。网格是不规则的,所以现在我一直在创建一个散点图并将值分成多个箱子,以显示为下面链接中 img 上的等高线。 http://i.stack.
这个问题在这里已经有了答案: Test if a numpy array is a member of a list of numpy arrays, and remove it from the
我有一个存储为栅格的高程图。我想将平滑的“vector ”曲线拟合到恒定高度的轮廓。在我的应用程序中,数据实际上是地理海拔,但问题可以推广到两个变量的任何函数。 如果有帮助,我可以生成另一个具有抗锯齿
我想生成一个带有颜色条的等高线图/热图,然后添加一个注释框。这个数字很丑,但得到了我想要的: add_subplot() 是不够的。如果我尝试将所有内容都放在同一个子图中,则该框会被遮盖。我可以通过使
我正在尝试使用属于 ROOT 的 Minuit2 最小化器为具有物理限制的参数生成等高线图数据分析框架。不幸的是,当我尝试生成等高线图时,Minuit2 似乎有意将参数漂移到超出其限制的区域: >>>
我的目标是这种效果:(仅水平轮廓线): 我确实找到了 this example ,但是它会创建水平 和 垂直轮廓线。我无法完全理解如何调用 fwidth()正在生成线条。 uniform float
大家好,我是编程新手,我正在尝试做一些可能非常明显的事情,但对于我来说,我无法弄明白。我有一系列 x、y、z 数据(在我的例子中,对应于距离、深度和 pH 值)。我想使用 matplotlib 在 x
我是一名优秀的程序员,十分优秀!