Python Matplotlib:对齐图形最左侧的文本
我试图找出如何在matplotlib中将文本与图形最左边对齐。我可以通过硬编码值来实现这一点(在下面的示例中为x=-.98),但是这需要大量的尝试和错误 是否可以返回图形边框的坐标(而不是图形边框)或将文本设置为从图形的最左侧开始Python Matplotlib:对齐图形最左侧的文本,python,matplotlib,text,alignment,Python,Matplotlib,Text,Alignment,我试图找出如何在matplotlib中将文本与图形最左边对齐。我可以通过硬编码值来实现这一点(在下面的示例中为x=-.98),但是这需要大量的尝试和错误 是否可以返回图形边框的坐标(而不是图形边框)或将文本设置为从图形的最左侧开始 # matplotlib example of text align import matplotlib.pyplot as plt # x and y axis data y_axis_labels = ['y-label-1','y-label-2','y-la
# matplotlib example of text align
import matplotlib.pyplot as plt
# x and y axis data
y_axis_labels = ['y-label-1','y-label-2','y-label-3','y-label-4']
x_axis_labels = [1,2,3,4]
# create horizontal bar plot
fig, ax = plt.subplots()
ax.barh(y_axis_labels, x_axis_labels)
# Align the text with the far left of the y_axis labels
plt.text(x=-.98,y=4, s='start at far left', color='red')
plt.show()
谢谢 更换
plt.text(x=-.98,y=4, s='start at far left', color='red')
与
这不是他需要的谢谢你的答复。这会将文本放在图形的左侧,但不会放在图形的左侧。在水平条形图中,它会将文本与条形图的边缘对齐,而不是与y轴标签的边缘对齐。请尝试此
plt.title('haha',x=-0.14049,y=0.98)
?
ax.set_title('start at far left',loc='right',color='red' )