在matplotlib中需要帮助来找出答案,
如何使箭头朝上,箭头指向曲线/线上的曲线?
如何调整绘图的范围/限制,使其边缘在图表上清晰可见?
我想在脉冲波的上升沿添加箭头,(脉冲下降沿上的向下箭头将是奖励)并且无法找到一种简单的方法(注释上的示例)页面完全有不同的用途。)
由于图片使事情更清晰,我的代码是:
from pylab import *
# How do I have arrows pointing up for every even value and pointing down for every odd value along Y axis for the highest freq.
baseFreqTimePeriod = 100
samplingFreqTimePeriod = 0.001
numberOfPulses = 10
def baseFreq(inputTime, timePeriod):
sampleWindow = timePeriod
return [ (1.0/(timePeriod/baseFreqTimePeriod)) if((i % sampleWindow) <= (sampleWindow / 2)) else 0.0 for i in inputTime ]
'''
output = []
for i in inputTime:
sampleIsAtPosition = i % sampleWindow
if(sampleIsAtPosition <= (sampleWindow / 2)):
output.append(1.0/(timePeriod/baseFreqTimePeriod))
else:
output.append(0.0)
return output
'''
t = arange(0.0, numberOfPulses * baseFreqTimePeriod, samplingFreqTimePeriod)
baseFreqFn = baseFreq(t, baseFreqTimePeriod)
plot(t, baseFreqFn, linewidth=1.0)
baseFreqFn = baseFreq(t, 2 * baseFreqTimePeriod)
plot(t, baseFreqFn, linewidth=2.0)
baseFreqFn = baseFreq(t, 3 * baseFreqTimePeriod)
plot(t, baseFreqFn, linewidth=2.0)
xlabel('time (uS)')
ylabel('Amplitude')
title('Test')
grid(True)
show()
这会生成输出:
相反,这会让我感到高兴(只画出前几个箭头)
另外,请注意图形的显示窗口如何成为全振幅波形剪辑的顶部? (底部位也被遮挡)
如果我能看到峰峰值(轴延伸超出数据范围)会很棒,如下所示:
(http://web.mit.edu/6.02/www/f2009/handouts/labs/lab2_7_1.png)
答案 0 :(得分:2)
要制作箭头,您可以使用arrow
例程:
#x,y, dx, dy,
arrow(0,0, 0,1.0,
'lw':2,
'color':'black',
'head_width':baseFreqTimePeriod/4,
'head_length':0.05
制作向下箭头,设置负dy。:
arrow(baseFreqTimePeriod,0, 0,-1.0,
'lw':2,
'color':'black',
'head_width':baseFreqTimePeriod/4,
'head_length':0.05
要更改图表的限制,请使用xlim
和`ylim':
ylim([-.2,1.2])
xlim([-.1*t[-1],t[-1]*1.1])