我想在python中创建一个图形,并使得相同的annonate文本将具有两种颜色,annonate的一半将是蓝色,另一半将是红色。matplotlib两种不同的颜色在相同的注释
我认为代码可以解释它自己。我有3行1绿色与绿色annonate,1蓝色与蓝色annone。
第三个是红色的情节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你看看[这个问题](https://stackoverflow.com/questions/9169052/partial-coloring-of-text-in-matplotlib)? – ImportanceOfBeingErnest
谢谢。这个答案确实非常相关:https://stackoverflow.com/a/42768093/1878788 – bli