내 포인트에 대한 수직 화살표를 플롯
-
21-12-2019 - |
문제
각 데이터 포인트를 가리키는 수직 화살표를 추가하는 방법을 알아 내려고합니다.나는 아래에 분산 된 플롯과 코드를 가지고 있습니다.그래프 스케일이 약 0.2의 길이로 올라가는 점에서 시작하기 위해 수직 화살표가 필요합니다.
import matplotlib.pyplot as plt
fig = plt.figure()
a1 = fig.add_subplot(111)
simbh = np.array([5.3, 5.3, 5.5, 5.6, 5.6, 5.8, 5.9, 6.0, 6.2, 6.3, 6.3])
simstel =np.array([10.02, 10.08, 9.64, 9.53, 9.78, 9.65, 10.05, 10.09, 10.08, 10.22, 10.42])
sca2=a1.scatter(simstel, simbh )
.
해결책
제시된 다른 접근법은 훌륭합니다.오늘 해안상 상황을 가고 있습니다 :
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
simbh = np.array([5.3, 5.3, 5.5, 5.6, 5.6, 5.8, 5.9, 6.0, 6.2, 6.3, 6.3])
simstel = np.array([10.02, 10.08, 9.64, 9.53, 9.78, 9.65, 10.05, 10.09, 10.08, 10.22, 10.42])
sca2 = ax.scatter(simstel, simbh)
for x, y in zip(simstel, simbh):
ax.annotate('', xy=(x, y), xytext=(0, 25), textcoords='offset points',
arrowprops=dict(arrowstyle="<|-"))
.
다른 팁
비트 해킹, 그림이 올바르게 보일 때까지 arrow_offset
및 arrow_size
를 조정하십시오.
import matplotlib.pyplot as plt
fig = plt.figure()
a1 = fig.add_subplot(111)
simbh = np.array([5.3, 5.3, 5.5, 5.6, 5.6, 5.8, 5.9, 6.0, 6.2, 6.3, 6.3])
simstel =np.array([10.02, 10.08, 9.64, 9.53, 9.78, 9.65, 10.05, 10.09, 10.08, 10.22, 10.42])
sca2=a1.scatter(simstel, simbh, c='w' )
arrow_offset = 0.08
arrow_size = 500
sca2=a1.scatter(simstel, simbh + arrow_offset,
marker=r'$\uparrow$', s=arrow_size)
. 이 작업을 직접 수행 할 수 있습니다
from matplotlib import pyplot as plt
import numpy as np
# set up figure
fig, ax = plt.subplots()
# make synthetic data
x = np.linspace(0, 1, 15)
y = np.random.rand(15)
yerr = np.ones_like(x) * .2
# if you are using 1.3.1 or older you might need to use uplims to work
# around a bug, see below
ax.errorbar(x, y, yerr=yerr, lolims=True, ls='none', marker='o')
# adjust axis limits
ax.margins(.1) # margins makes the markers not overlap with the edges
.
이러한 화살표가 의미가 바뀌 었는지, 'LOLIMS'가 '데이터 포인트가 하한'이고 '데이터 포인트가 최대 값'이란 것을 의미합니다. https://github.com/matplotlib/matplotlib/pull/2452./a.>
이것은 슈퍼 우아하지는 않지만 트릭은
화살표가 데이터 포인트에서 시작하고 0.2 단위로 올라가십시오.
for x,y in zip(simstel,simbh):
plt.arrow(x,y,0,0.2)
.
제휴하지 않습니다 StackOverflow