[英]How can I do to center my text using matplotlib?
您好,使用 matplotlib 有此代码:
import matplotlib.pyplot as plt
from matplotlib import gridspec
Figure = plt.figure()
gs = gridspec.GridSpec(1, 3)
ax0 = Figure.add_subplot(gs[0, 0])
ax = Figure.add_subplot(gs[0, 2])
ax1 = Figure.add_subplot(gs[0, 1])
ax1.text(0, 0, 'Hello everybody',
color="white", style='oblique', ha='left', wrap=True, horizontalalignment='center', verticalalignment='center',
bbox={'facecolor': "#34C8EC", 'boxstyle': 'round,pad=1'})
Figure.canvas.draw_idle()
plt.show()
我有以下问题:
我想将我的文本居中。 我怎样才能做到这一点?
import matplotlib.pyplot as plt
from matplotlib import gridspec
Figure = plt.figure()
gs = gridspec.GridSpec(1, 3)
ax0 = Figure.add_subplot(gs[0, 0])
ax = Figure.add_subplot(gs[0, 2])
ax1 = Figure.add_subplot(gs[0, 1])
ax1.text(.5, .5, 'Hello everybody',
color="white", style='oblique', ha='center', va='center',
bbox={'facecolor': "#34C8EC", 'boxstyle': 'round,pad=1'})
Figure.canvas.draw_idle()
plt.show()
in plt.text first x and y are the position to place the text for more reading go through the documentation https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.text.html
给定代码的output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.