centering xticks in bar plot

Friends,

Attached a script test.py and 2 data files using with which i am trying to make a bar plot. The output is coming nice, but the x-ticks are placed at the left edge of the first bar. I want to make the xticks at the center between the two bars to have a better visualization. I dnt get which arguement i should use to get the xticks at the center of the two bars as in the following example

http://matplotlib.sourceforge.net/examples/pylab_examples/barchart_demo.html

Thanks,
Bala

test.py (578 Bytes)

T1.sasa (948 Bytes)

T2.sasa (947 Bytes)

Bala,

There are two issues with your current code. First, you are setting the x limits of your plot to [1, 40], which causes the last red bar to be clipped out. You should set it to [1, 40 + width]. Second, the set_xticks() needs to be shifted by width. However, doing so will change the values. So, it seems that if you change

ax.set_xticks(ind)

to

plt.xticks(ind + width, ind)

The ticks will be placed at the positions ‘ind + width’, but with the values ‘ind’. I hope this helps.

Ben Root

···

On Mon, Jul 19, 2010 at 9:55 AM, Bala subramanian <bala.biophysics@…287…> wrote:

Friends,

Attached a script test.py and 2 data files using with which i am trying to make a bar plot. The output is coming nice, but the x-ticks are placed at the left edge of the first bar. I want to make the xticks at the center between the two bars to have a better visualization. I dnt get which arguement i should use to get the xticks at the center of the two bars as in the following example

http://matplotlib.sourceforge.net/examples/pylab_examples/barchart_demo.html

Thanks,
Bala