Python 在matplotlib绘图上剪切文本
我正在绘图,我希望文本在边缘裁剪。现在它挂在边缘上,这对可读性很好,但不是我真正想要的 下面是我正在做的一个玩具版本:Python 在matplotlib绘图上剪切文本,python,matplotlib,Python,Matplotlib,我正在绘图,我希望文本在边缘裁剪。现在它挂在边缘上,这对可读性很好,但不是我真正想要的 下面是我正在做的一个玩具版本: import numpy as np import matplotlib.pyplot as plt %matplotlib inline fig = plt.figure() ax = fig.add_subplot(111) ax.scatter(np.random.random(10), np.random.random(10)) ax.text(0.8, 0.5,
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(np.random.random(10), np.random.random(10))
ax.text(0.8, 0.5, "a rather long string")
plt.show()
为了清楚起见,我想裁剪我的
文本
元素,但不想裁剪任何其他元素-例如,我想将0.9
单独保留在x轴上。您应该将文本的剪贴簿设置为:
这导致
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(np.random.random(10), np.random.random(10))
ax.text(0.8, 0.5, "a rather long string",
clip_box=ax.clipbox, clip_on=True)
ax.set_xlim(0, 1)
plt.show()