Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 270
Erotemic Avatar asked Dec 20 '22 21:12

Erotemic


2 Answers

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")

like image 116
Paul H Avatar answered Jan 07 '23 01:01

Paul H


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

like image 33
Sleepyhead Avatar answered Jan 07 '23 02:01

Sleepyhead