Python 是否可以从matplotlib中记号下方的某个位置绘制箭头
我想画一个这样的情节 棘手的是从“z=-1.48”到x轴的箭头,它位于刻度线下 下面显示的代码是我试图绘制箭头的代码Python 是否可以从matplotlib中记号下方的某个位置绘制箭头,python,matplotlib,Python,Matplotlib,我想画一个这样的情节 棘手的是从“z=-1.48”到x轴的箭头,它位于刻度线下 下面显示的代码是我试图绘制箭头的代码 import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm fig, ax = plt.subplots(figsize=(8,3)) x = np.linspace(-5,5,101) x2 = np.linspace(-5,-1.5,101) y = norm.pdf(x)
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
fig, ax = plt.subplots(figsize=(8,3))
x = np.linspace(-5,5,101)
x2 = np.linspace(-5,-1.5,101)
y = norm.pdf(x)
y2 = norm.pdf(x2)
t = ax.text(-3, 0.15, '-1.5')
plt.grid(True)
ax.plot(x, norm.pdf(x))
ax.fill_between(x2, 0, y2, color='r')
不幸的是,“记号”下的部分无法渲染
是否可以使勾号下的箭头显示?是否需要
注释
:
ax.annotate('1.5',
xy=(-1.5, 0),
xytext=(-1.5, -0.1),
ha='center',
va='center',
arrowprops={'arrowstyle': '->'})
这将文本放置在xytext
处,并从那里绘制一个指向xy
的箭头ha
和va
是指基于这些坐标的文本对齐方式。如果您没有通过“居中”
,箭头和文本将略微错位。最后,传递arrowprops
可以让您受益于内置的箭头样式
有关更多信息,请参阅