Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude lines from autoscale in matplotlib

Tags:

matplotlib

I have a somewhat complex plot task in matplotlib that requires--I think--an autoscale() function that excludes certain plotted lines.

The built-in autoscale_view() function in matplotlib gets the union of all the bboxes of the axis and then scales based on that. I've made a loose_autoscale_view that adds a margin factor to it. But both determine scaling based on all the points on the axis. I don't want that, as I want some points to live in the bottom margin.

I need to make an autoscale function in which I do something like:

1) Get the lines I want and exclude the ones I don't (I could pass in an excluded_lines arg). What is the function for getting lines from an axis? I couldn't find it.

2) Get the bboxes for those lines and use a similar approach as autoscale_view(). How can I get the bbox associated with a line?

My 1&2 may be totally off-base, too--just suggesting the approach I was considering.

like image 823
Che M Avatar asked Dec 27 '25 22:12

Che M


1 Answers

from matplotlib import pyplot as plt
plt.plot([1,2,3],[3,4,5])
plt.plot([2,3,4],[4,9,4])
ax = plt.gca()
l = ax.get_lines()[0]  # a line instance
p = l.get_path()
p.get_extents() # a bbox instance
like image 197
Paul Avatar answered Dec 30 '25 23:12

Paul