## [Matplotlib-users] clipping feature?

 [Matplotlib-users] clipping feature? From: James Boyle - 2004-02-25 17:56:53 ```If I set the axis limits to a value less than the actual domain of the data, the line is not extended to the edge of the plot but rather is only drawn to the final point within the domain. The following illustrates what I mean: ax = subplot(111) plot([1,2,3,4],'bo', [1,2,3,4],'k') axis([0.,2.4,1.,4.]) The plot stops at the point (2,3) although the data go to (3,4). When I have dealt with these issues, I usually draw the line to its full extent and then clip the line so it stops at the edge of the plot frame. I set the axis bounds when I am plotting a number of lines some of which have a larger domain. While interested in the behaviour in the limited domain, I would like to retain the information that some lines extend beyond. When I first encountered this behaviour, I thought that I had mistakenly truncated my input data - I think that the plot should show as much of the data passed to it as possible. Is there something I am missing - or is this a feature? JIm ```

 [Matplotlib-users] clipping feature? From: James Boyle - 2004-02-25 17:56:53 ```If I set the axis limits to a value less than the actual domain of the data, the line is not extended to the edge of the plot but rather is only drawn to the final point within the domain. The following illustrates what I mean: ax = subplot(111) plot([1,2,3,4],'bo', [1,2,3,4],'k') axis([0.,2.4,1.,4.]) The plot stops at the point (2,3) although the data go to (3,4). When I have dealt with these issues, I usually draw the line to its full extent and then clip the line so it stops at the edge of the plot frame. I set the axis bounds when I am plotting a number of lines some of which have a larger domain. While interested in the behaviour in the limited domain, I would like to retain the information that some lines extend beyond. When I first encountered this behaviour, I thought that I had mistakenly truncated my input data - I think that the plot should show as much of the data passed to it as possible. Is there something I am missing - or is this a feature? JIm ```
 Re: [Matplotlib-users] clipping feature? From: John Hunter - 2004-02-25 18:18:31 ```>>>>> "James" == James Boyle writes: James> I set the axis bounds when I am plotting a number of lines James> some of which have a larger domain. While interested in the James> behaviour in the limited domain, I would like to retain the James> information that some lines extend beyond. When I first James> encountered this behaviour, I thought that I had mistakenly James> truncated my input data - I think that the plot should show James> as much of the data passed to it as possible. James> Is there something I am missing - or is this a feature? It's a feature! matplotlib does two kinds of clipping: data clipping and viewport clipping. Viewport clipping is the typical clipping where the lines are clipped to the viewport. data clipping throws out all points not in the viewport. I work with very long data sets of which only a small portion is in the viewport, and use the interactive navigation controls to scroll trough it. I found it was much more efficient to first clip the data with Numeric before plotting it. See examples/stock_demo.py, of which only a few days of 60 days of data are initially in the viewport. You can control this in a couple of ways: from matplotlib.matlab import * ax = subplot(111) line1, line2 = plot([1,2,3,4],'bo', [1,2,3,4],'k') line1.set_data_clipping(False) line2.set_data_clipping(False) axis([0.,2.4,1.,4.]) show() Or edit the init function of lines.Line2D to turn data clipping off by default self._useDataClipping = False I've been meaning to make a matplotlibrc file to control things like default line width, color, fontsize and name, antialiasing, data clipping and so on. JDH ```
 Re: [Matplotlib-users] clipping feature? From: matthew arnison - 2004-02-25 22:35:50 ```I suggest to John a while back that for plotting it makes more sense for data ranges to be inclusive [] or min <= x <= max rather than half-inclusive [) or min <= x < max as is the python default for functions like range(). Specifically, what about making the default behaviour to clip the data at the first point which is equal or greater than the axis range? That should maintain the efficiency gains of clipping, while still keeping the scientific plotting behaviour that I think most users are accustomed to. Cheers, Matthew. ```
 Re: [Matplotlib-users] clipping feature? From: John Hunter - 2004-03-01 14:26:08 ```>>>>> "matthew" == matthew arnison writes: matthew> Specifically, what about making the default behaviour to matthew> clip the data at the first point which is equal or matthew> greater than the axis range? That should maintain the matthew> efficiency gains of clipping, while still keeping the matthew> scientific plotting behaviour that I think most users are matthew> accustomed to. Hi Matthew - That's a good idea - the data clipping feature was a gotcha for many. For the next release, I turned data clipping off by default since I don't think it's the typical use case and implemented the "first point which is equal or greater" suggestion. However, I also have created a config file, so you can set the default as you like. JDH ```
 [Matplotlib-users] how to set the legend location? From: matthew arnison - 2004-03-05 05:07:16 ```Hi Now that we have the lovely new syntax for setting legend labels for each line: plot(x, sin(x), label='sin(x)') plot(x, cos(x), label='cos(x)') how do we then move the legend from the default upper right location? legend() turns the legend on, but the LOC argument has to be second or third, after the LINES and/or LABELS. What about a new loc keyword for legend? E.g. legend(loc=5) While we're talking about problems inherited from matlab's use of positional arguments, is there some easy way to set the x or y axis limits without setting the other axis? E.g. if I want to leave the x axis automatic, but manually set the y axis? I looked at help(axis) and at http://matplotlib.sourceforge.net/matlab_commands.html and I couldn't see anything obvious like xaxis or yaxis functions. This works: autoaxis = axis() autoaxis[2:4] = (ymin, ymax) axis(autoaxis) but what if I add a plot afterwards that changes the x axis limits? And it seems like hard work compared to: yaxis(ymin, ymax) Cheers, Matthew. ```