2

matplotlib示例页面中的第一个示例为例,

import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)


# Create a simple contour plot with labels using default colors.  The
# inline argument to clabel will control whether the labels are draw
# over the line segments of the contour, removing the lines beneath
# the label
plt.figure()
CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=10)
plt.title('Simplest default with labels')

plt.savefig('plot.pgf')

我遇到的问题是靠近轴的轮廓标签(这里是最顶部的“0.000”)超出图形边界。这是我使用 LaTeX 得到的输出: 使用 PGF/LaTeX 生成的等高线图 如您所见,顶部的标签“0.000”与黑线重叠。

我能做些什么来解决这个问题吗?需要明确的是,我的问题不是标签靠近轴。我想要的是与matplotlib页面上显示的相同的行为,即绘图内容被剪切到图形区域,切断文本和线条。

4

1 回答 1

0

(#11375)的相应错误报告matplotlib所示,matplotlib的 PGF 后端不支持文本剪辑,这导致了这个问题,今天似乎仍然存在。

于 2021-05-14T16:19:13.173 回答