2

I am doing a simple scatterplot using Pythons scatterplot. But no matter how I set my axis, and no matter that I don't have any negative values I get negative values at the x-axis. How do I force the axis to start at 0?

My code:

fig, ax = plt.subplots(1)
ax.scatter(lengths,breadths, alpha=0.3, color="#e74c3c", edgecolors='none')
spines_to_remove = ['top', 'right']
for spine in spines_to_remove:
    ax.spines[spine].set_visible(False)
ax.xaxis.set_ticks_position('none')
ax.yaxis.set_ticks_position('none')
ax.xaxis.set_view_interval(0,400)
ax.yaxis.set_view_interval(0,90)
figname = 'scatterlengthsbreadths.pdf'
fig.savefig(figname, bbox_inches='tight')  

1 Answer 1

6

You can use ax.set_xlim(lower_limit, upper_limit) to choose your x-limits. Note that there is a similar command ax.set_ylim for the y-limits.

Note that if you're just using the pyplot interface, i.e. without using fig and ax, then the command is plt.xlim().

For example:

import matplotlib.pyplot as plt

x = [1,2,3]
y = [4,5,6]

fig, ax = plt.subplots()

ax.plot(x, y)

ax.set_xlim(0, 10)

plt.show()

enter image description here

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

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.