i've been struggling while , hoping it's simple oversight, is.
i want align 2 rows of text columns. i'm attempting .format string method.
import matplotlib.pyplot plt bank_percentage=[.33,.25,.08,.15,.07,.08,.11,.3] percent_text1 = "b0:{:>10.2%} b1:{:>10.2%} b2:{:>10.2%} b3:{:>10.2%}".format( bank_percentage[0],bank_percentage[1],bank_percentage[2],bank_percentage[3]) percent_text2 = "b4:{:>10.2%} b5:{:>10.2%} b6:{:>10.2%} b7:{:>10.2%}".format( bank_percentage[4],bank_percentage[5],bank_percentage[6],bank_percentage[7]) fig5= plt.figure(5) ax = fig5.add_subplot(111) plt.plot([1,2,3],[1,2,3]) plt.xlabel('time (ms)') plt.ylabel('number of active banks') plt.title('active banks') ax.text(0.02,0.01, percent_text2, transform=ax.transaxes, fontsize=12, va='bottom', ha='left', backgroundcolor='black', color='white',weight='bold') ax.text(0.02,.05, percent_text1, transform=ax.transaxes, fontsize=12, va='bottom', ha='left', backgroundcolor='black', color='white',weight='bold') plotting shows each element gets further out of alignment.
you formatted text correctly, matpllotlib uses serif font, spaces don't show how expect. add following , works:
ax.text( stuff, family='monospace' )
Comments
Post a Comment