Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clip_on = False does not work for x-axis #2675

Merged
merged 1 commit into from Jan 28, 2014

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Jan 21, 2014

When I set clip_on = False the curve extends beyond the y-limits, but it does not extend beyond the x-limits. Am I doing something wrong, or is this a bug?

For example, the following code:

import matplotlib.pyplot as plt
import numpy as np
x1 = np.arange(-10, 10, 0.01)
y1 = x1
ax = plt.subplot()
ax.set_xlim(-2,2)
ax.set_ylim(-1,1)
ax.plot(x1, y1, clip_on = False)

produces the plot I would expect:

good

However, all I have to do is change the y-limits,

fig = plt.figure()
ax = plt.subplot()
ax.set_xlim(-2,2)
ax.set_ylim(-3,3)
ax.plot(x1, y1, clip_on = False)

and I get the following plot:

bad

Why does the first plot extend beyond the y-limits, while the second one does not extend beyond the x-limits? In case it matters, I am using matplotlib 1.3.0 with the TkAgg backend, but apparently (http://stackoverflow.com/questions/20523752/matplotlib-clip-on-false-does-not-work-on-x-axis) it also happens with the MacOSX backend.

@cimarronm
Copy link
Contributor

This isn't a bug but a result of a feature that was added to speed up plotting operations (I'm guessing zooming on a plot with a large number of data points) where it subslices the datapoints by the x limits so the dataset is already clipped.

In fact, if you look at the code, there is an arbitrary number of points (100) chosen where if the number of points is smaller, it will not subslice and you will get what you were expecting. For example, if you change x1 to x1 = np.arange(-10, 10, 0.5) so that there is less than 100 points you will see it works just fine.
image

It seems to me like the hardcoded 100 number in the lines.recache function below should be made into a parameter (but I do not like hardcoded numbers unless the constant is inherently intertwined with the very functionality itself)

        self._subslice = False
        if (self.axes and len(x) > 100 and self._is_sorted(x) and
                self.axes.name == 'rectilinear' and
                self.axes.get_xscale() == 'linear' and
                self._markevery is None):
            self._subslice = True

Also, it seems like a better approach might be to subslice based upon the figure box dimensions rather than the x limits so one could get the line to extend past the axes as in the example given with clip_on=False.

@mdboom
Copy link
Member

mdboom commented Jan 21, 2014

I think the far better approach is to just make this optimization respect the clip setting of the line (attached).

Cc: @efiring, as I think you are the one who wrote this optimization.

@cimarronm
Copy link
Contributor

Looks good to me. The optimization will not take place then but if you the user is turning off clip perhaps they should expect anything like that as they are doing something more advanced.

pelson added a commit that referenced this pull request Jan 28, 2014
clip_on = False does not work for x-axis
@pelson pelson merged commit 4507c9b into matplotlib:master Jan 28, 2014
@mdboom mdboom deleted the clip-only-when-clipping-is-on branch August 7, 2014 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants