matplotlib PGF输出:轮廓标签超出图边界

时间:2018-05-27 17:41:02

标签: python matplotlib pgf

matplotlib examples page中获取第一个例子,

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获得的输出: Contour plot produced with PGF/LaTeX 如您所见,顶部的标签“0.000”与黑线重叠。

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

1 个答案:

答案 0 :(得分:0)

corresponding bug report for matplotlib (#11375) 所示,matplotlib 的 PGF 后端不支持文本剪辑,这导致了这个问题,今天似乎仍然存在。