why using matplotlib text alignent with string format functions works wrong?
<p>I am trying to align my texts to right in matplotlib bars. The following codes works just fine:</p>

<pre><code>colors = ['red', 'blue', 'green', 'yellow']
for color in colors:
    print('{:&gt;15}'.format(color))
</code></pre>

<p>output:</p>

<pre><code>        red
       blue
      green
     yellow
</code></pre>

<p>However, the same string format doesn't work in plt.text functions:</p>

<pre><code>fig, ax = plt.subplots()
bar_band = ax.barh(range(len(colors)), np.ones(len(colors)), height=1)
for i in range(len(colors)):
    bar_band[i].set_color(colors[i])
    ax.text(0.1, i+0.4, "{:&gt;15}".format(colors[i]))

ax.set_axis_off()
plt.show()
</code></pre>

<p>I got texts aligns to center instead. Can any one help me on this?</p>

<p><a href="http://i.stack.imgur.com/mki3f.png" rel="nofollow">enter image description here</a></p>

<p><a href="http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.text" rel="nofollow"><code>ax.text()</code></a> creates a matplotlib <code>Text</code> object, which have the option <a href="http://matplotlib.org/api/text_api.html#matplotlib.text.Text.set_horizontalalignment" rel="nofollow"><code>horizontalalignment</code></a> (or <code>ha</code> for short). This can help you to align the text to your desired position.</p>

<p>Accepted options are <code>'left'</code>, <code>'right'</code> and <code>'center'</code></p>

<p>So, you might try: </p>

<pre><code>ax.text(0.1, i+0.4, "{:&gt;15}".format(colors[i]), ha='right')
</code></pre>

python string matplotlib plot text-alignment