开发者

exclude lines from autoscale in matplotlib

开发者 https://www.devze.com 2023-02-20 09:03 出处:网络
I have a somewhat complex plot task in matplotlib that requires--I think--an autoscale() function that excludes certain plotted lines.

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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消