【发布时间】:2014-06-08 16:07:46
【问题描述】:
我正在尝试在 python 中创建一个图形,并且使相同的 annonate 文本具有两种颜色,一半 annonate 将是蓝色,另一半将是红色。
我认为代码可以自我解释。我有 3 行,1 条绿色带绿色番石榴,1 条蓝色带蓝色番石榴。
第三个是红色,它是情节 1 和情节 2 的总和,我希望它有一半的蓝色和一半的绿色。
ipython -pylab
x=arange(0,4,0.1)
exp1 = e**(-x/5)
exp2 = e**(-x/1)
exp3 = e**(-x/5) +e**(-x/1)
figure()
plot(x,exp1)
plot(x,exp2)
plot(x,exp1+exp2)
title('Exponential Decay')
annotate(r'$e^{-x/5}$', xy=(x[10], exp1[10]), xytext=(-20,-35),
textcoords='offset points', ha='center', va='bottom',color='blue',
bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3),
arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.95',
color='b'))
annotate(r'$e^{-x/1}$', xy=(x[10], exp2[10]), xytext=(-5,20),
textcoords='offset points', ha='center', va='bottom',color='green',
bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3),
arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=-0.5',
color='g'))
annotate(r'$e^{-x/5} + e^{-x/1}$', xy=(x[10], exp2[10]+exp1[10]), xytext=(40,20),
textcoords='offset points', ha='center', va='bottom',
bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3),
arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=-0.5',
color='red'))
有可能吗?
【问题讨论】:
-
@bli 你看this question了吗?
-
谢谢。这个答案确实很相关:stackoverflow.com/a/42768093/1878788
标签: python matplotlib