0

I can't find a way to control the alignment of points in matplotlib.pyplot in order to more properly center samples within a window. Below is an example where I am plotting two averaged samples with stdev and instead of being uniformly spaced within the window, they are pushed off onto the edges of the plot.

Is there a way to better control this alignment? My code is below for reference.

plt.clf()
plt.errorbar(np.arange(len(rmean)),rmean,yerr=rstddev, linestyle="None", fmt='o')
plt.xlabel('Probes', fontsize=1)
plt.ylabel('VAF')
plt.title('Average VAF Along Probed Regions')
plt.tight_layout()
plt.xticks(np.arange(len(rmean)),labels,rotation='90')
plt.tight_layout()
plt.show()

enter image description here

2 Answers 2

3

I guess you've already know this from Matplotlib Examples. Essentially, the x-axis position of your data is defined by "x", which is np.arange(len(rmean)). Therefore, the final visual position is related to the range of x-axis, the xlim. Then one potential solution is to set xlim by plt.xlim([-1, len(rmean)]). I don't have your rmean or rstddev. But testing by some fake data, I got this: enter image description here Hopefully, this is what you want.

Sign up to request clarification or add additional context in comments.

Comments

2

You may manually set the limits on the xaxis to give more space. Here you have values of 0 and 1 on the axis, so setting e.g. plt.xlim(-2,3) gives you some more space.

You could also automatically assign some proportion of the axes to be left free, e.g. to get 50% margin, you'd do

plt.margins(x=0.5)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.