파이썬으로 그림을 만들고 make는 동일한 annonate 텍스트가 두 가지 색상을 가지므로 annonate의 절반이 파란색이고 나머지 절반은 빨간색입니다.matplotlib 동일한 주석의 두 가지 다른 색상
코드 자체를 설명한다고 생각합니다. 나는 3 줄의 초록색 녹색 초록색 1 개, 파란색 1 개 파란색과 파란색 1 개가있다.
제 3의 빨간색은 음모 1과 음모 2의 합계이며, 나는 파란색으로 절반과 파란색으로 절반 음표를 갖고 싶습니다. -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'))
ipython
은 가능합니까?
@bli [이 질문에 대한 답변] (https://stackoverflow.com/questions/9169052/partial-coloring-of-text-in-matplotlib)을 보았습니까? – ImportanceOfBeingErnest
감사합니다. 이 대답은 실제로 적절합니다. https://stackoverflow.com/a/42768093/1878788 – bli