[英]How to dynamically update matplotlib plot using images instead of markers
[英]Using numbers as matplotlib plot markers
我有一個1-D numpy數組,我想要繪制,我希望繪圖標記是一個數字,顯示元素的位置。 例如,如果我的數組是[2.5,4,3]
那么我希望繪圖在點(0,2.5)處為0,在(1,4)處為1,在(2,3)處為2上。
這該怎么做?
你需要在for循環中調用pylab.text()
:
import pylab as pl
xs = [0, 1, 2]
ys = [2.5, 4, 3]
pl.plot(xs, ys, "-o")
for x, y in zip(xs, ys):
pl.text(x, y, str(x), color="red", fontsize=12)
pl.margins(0.1)
可能不鼓勵使用pylab(我必須查看pylab是什么)。
import matplotlib.pyplot as plt
xs = [0, 1, 2]
ys = [2.5, 4, 3]
plt.plot(xs, ys, "-o")
for x, y in zip(xs, ys):
plt.text(x, y, str(x), color="red", fontsize=12)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.