question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

xlim/ylim options to set visible domain limits indirectly by adjusting camera

See original GitHub issue

Describe what feature you would like added.

Matplotlib 2d plots allow xlim and ylim options to set visible axes limits.

In vtk/pyvista, in normal plane views (e.g., camera_position='xy'), this can be achieved by adjusting camera position, focal points, and elevation angle.

It would be convenient to have xlim and ylim options to do this automatically

One possible implementation is to reuse the existing codes that set pre-defined views for special camera_positoin, e.g., the view_xy, by using the dimension of a ``virtual’’ plane with the desired bounds.

Of course, we may pass the data to Matplotlib directly for drawing, but this is not always straightforward for unstructured grid.

Currently, my manual solution to set the normal view first (e.g., xy) with proper zooming, then shift the camera_position and focal_point by the same amount.

I apologize if pyvista already has a handy solution for this.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
banesullivancommented, Mar 9, 2022

I’d like to add a zoom_to_data() method that might help to this end.

A prototype of this method is:

def zoom_to_data(self, data):
    if not self.camera_set:
        self.view_isometric()
    self.reset_camera(bounds=data.bounds)
    self.camera_set = True
    self.reset_camera_clipping_range()

Which can be used like:

import pyvista as pv

a = pv.Sphere(radius=5)
b = pv.Sphere(radius=1)

p = pv.Plotter(notebook=0)
p.add_mesh(a, opacity=0.5)
p.add_mesh(b, color='red')
zoom_to_data(p, b)
p.show()

Screen Shot 2022-03-08 at 8 47 21 PM

This could then be used with a Plane to get the desired effect:


xylim = pv.Plane(i_size=10, j_size=10)

p = pv.Plotter(notebook=0)
p.add_mesh(b, color='red')
p.view_xy()
zoom_to_data(p, xylim)
p.show_bounds()
p.show()

Screen Shot 2022-03-08 at 8 51 28 PM


xylim = pv.Plane(i_size=1, j_size=1)

p = pv.Plotter(notebook=0)
p.add_mesh(b, color='red')
p.view_xy()
zoom_to_data(p, xylim)
p.show_bounds()
p.show()

Screen Shot 2022-03-08 at 8 51 42 PM

0reactions
liangwang0734commented, Mar 9, 2022

I can give it a try, but I can’t promise a timeline.

I now think the feature itself might be more clearly defined because we have 3d not 2d.

In normal views (like view_xy), it is clear. For an oblique angle view, I’m not sure how to use the three limits. We may guess what the user wants. For example, if xlim and ylim is give, we may set the bounds to a xy plane. If all of xlim, ylim, and zlim are given, the only thing we can reasonably do it to use a box with those limits.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Set Axis Range (xlim, ylim) in Matplotlib - Stack Abuse
In this tutorial, we'll take a look at examples of how to set the axis range (xlim, ylim) also known as X limit...
Read more >
xlim, ylim, zlim (MATLAB Functions)
xlim ([xmin xmax]) sets the axis limits in the current axes to the specified values. xlim('mode') returns the current value of the axis...
Read more >
Set or query x-axis limits - MATLAB xlim - MathWorks
xlim ( limits ) sets the x-axis limits for the current axes or chart. Specify limits as a two-element vector of the form...
Read more >
Set plot (axes) view "box" without affecting limits - Stack Overflow
It is easy to use set(gca, 'xlim', [limitsXOfSmallElement]) and set(gca, 'ylim', [limitsYOfSmallElement]) to set axis limits so that the small ...
Read more >
How to Change xlim & ylim Range | Draw Base R Scatterplot
How to change x-axis and y-axis limits in the R programming language. More details: https://statisticsglobe.com/ set -axis- limits - in -rR code ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found