Erotemic
Erotemic

Reputation: 5228

pyplot.scatter changes the data limits of the axis

I have some code which plots some points. I substituted ax.scatter for ax.plot so I could control the color of each point individually. However when I make this change the axis x and y ranges seem to increase.

I can't pinpoint why this is happening. The only thing I've changed is plot to scatter.

This code makes an axis that is too big

    ax.scatter(x, y, c=color_list, s=pts_size, marker='o', edgecolor='none')
    #ax.plot(x, y, linestyle='None', marker='o', markerfacecolor=pts_color, markersize=pts_size, markeredgewidth=0)

This code does the right thing (but I can't control the color)

    #ax.scatter(x, y, c=color_list, s=pts_size, marker='o', edgecolor='none')
    ax.plot(x, y, linestyle='None', marker='o', markerfacecolor=pts_color, markersize=pts_size, markeredgewidth=0)

Is there a way I can call scatter such that it doesn't mess with my current axis limits?

Upvotes: 5

Views: 3667

Answers (2)

Paul H
Paul H

Reputation: 68146

I would use ax.autoscale(enable=False) before your call to scatter.

If you want to limit autoscale's reach, set the axis kwarg to "x" (i.e. ax.autoscale(enable=False, axis="x")

Upvotes: 10

Sleepyhead
Sleepyhead

Reputation: 1021

You can control the x and y axes limits: plt.xlim(xmin,xmax) Same with y-axis

Upvotes: 2

Related Questions