Stack the lables of an axis with matplotlib
<p>I'm creating a bar graph and showing multiple values on the x axis. By default they are shown in series with a "," separating them as shown below. Instead of a coma how could I show the values stacked on top of each other as drawn on the image below? This would save space on the x-axis to allow for bigger graphs when I want to show multiple values. </p>

<pre><code>import pandas as pd
import matplotlib as plt

dfex = pd.DataFrame({'City': ['LA', 'SF', 'Dallas'],
 'Lakes': [3, 9, 6],
 'Rivers': [1, 0, 0],
 'State': ['CA', 'CA', 'TX'],
 'Waterfalls': [2, 4, 5]})

myplot = dfex.plot(x=['City','State'],kind='bar',stacked='True')
</code></pre>

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

<p>You can simply hack the x-axis tick labels to achieve what you want.</p>

<pre><code>ticks = myplot.xaxis.get_ticklabels()
new_ticks = ['\n'.join(t.get_text()[1:-1].split(', ')) for t in ticks]
myplot.xaxis.set_ticklabels(new_ticks)
</code></pre>

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

python matplotlib