Text
Add text or formulas for the plots, anyway, it is to add a text
Reference Links: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.text.html#matplotlib.pyplot.text
Reference links (application): https://matplotlib.org/tutorials/text/text_intro.html#sphx-glr-tutorials-text-text-intro-py
Simple to use: (for more examples see application)
Parameter Description #: matplotlib.pyplot.text (X, Y, S, fontdict = None, withdash = <deprecated Parameter>, ** kwargs) S: added text time_text = ax.text (0.1, 0.9, '', transform ax.transAxes =) # when replacing text may time_text.set_text (time_template% (0.1 * i )) where time_template = 'time =% .1fs' , when this is convenient for replacement, if only once, then add, directly above write all like
Emerging issues:
*) The following code does not display text added, and finally found a reason to see axs.cla () reasons, so add axs.text directly animate in (....)
time_template='time=%.2fs' time_text=axs.text(0.1,0.90,"",transform=axs.transAxes) # def init(): # time_text.set_text("") # return time_text frames=bidirectional_bubble_sort(original_data_object) def animate(fi): bars=[] if len(frames)>fi: axs.cla() # axs.text(0.1,0.90,time_template%(0.1*fi),transform=axs.transAxes)#所以这样 time_text.set_text(time_template%(0.1*fi))#这个必须没有axs.cla()才行 axs.set_title('bubble_sort_visualization') axs.set_xticks([]) axs.set_yticks([]) bars=axs.bar(list(range(Data.data_count)),Number # [d.value for d in frames[fi]],#data 1, #宽度 color=[d.color for d in frames[fi]]#颜色 ).get_children() return bars anim=animation.FuncAnimation(fig,animate,frames=len(frames), interval=frame_interval,repeat=False)
transform
that transform conversion means, different coordinate systems are converted
Reference Links: https://matplotlib.org/users/transforms_tutorial.html
Take the example above is concerned, when you add text to plots, it uses a coordinate transformation
xs.text (0.1,0.90, time_template% (0.1 * fi), transform = axs.transAxes) # Here, transform = axs.transAxes axis coordinates is, probably means that the long axis of abscissas 0.1 times the distance left, from below 0.90 times the ordinate axis, if the default is not written, then coordinate data
, i.e., the horizontal axis is representative of 0.1 0.1 units, i.e., coordinate points