Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Zoom with Axes3D in Matplotlib

I am generating a 3D plot using matplotlib. I want to be able to zoom in on areas of interest. Currently, I am able to pan but not zoom. Looking at the mplot3d API, I learned about can_pan():

Return True if this axes supports the pan/zoom button functionality.

3D axes objects do not use the pan/zoom button.

and can_zoom():

Return True if this axes supports the zoom box button functionality.

3D axes objects do not use the zoom box button.

They both return False (I think can_pan returns False because the axes cannot pan AND zoom both but maybe I am reading the API wrong).

Is there a way to enable Zoom? The API indicates it does not use the buttons. Is there some way to enable zoom or set it so can_pan() and can_zoom() return True?

Here is a snippet of the code:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

data = np.genfromtxt('data_file.txt')

fig1 = plt.figure()
ax1 = fig1.gca(projection='3d')
ax1.scatter(data[:,0],data[:,1],data[:,2], c='r', marker='.')
plt.show()

ax1.can_zoom()
>>> False

ax1.can_pan()
>>> False

I am using Python 2.7 on an Ubuntu 14.04 64bit desktop version machine with matplotlib installed from the default repositories (I can look the versions up if that is pertinent).

like image 844
Steven C. Howell Avatar asked Aug 29 '14 20:08

Steven C. Howell


People also ask

How do I zoom in Matplotlib?

Press the right mouse button to zoom, dragging it to a new position. The x axis will be zoomed in proportionately to the rightward movement and zoomed out proportionately to the leftward movement. The same is true for the y axis and up/down motions.

How do you zoom a portion of image and insert in the same plot in Matplotlib?

MatPlotLib with Python Create x and y points, using numpy. To zoom a part of an image, we can make data for x and y points, in that range. Plot x and y points (Step 1), using the plot() method with lw=2, color red and label. Use the legend() method to place text for the plot, Main curve.


1 Answers

Actually @tcaswell is correct that this functionality doesn't exist and so it returns false. Have you tried zoom-to-rectangle button on the plot window? That works perfectly. If you haven't yet, then refer to the matplotlib instructions on Interactive Navigation. You can zoom in using two ways:

  1. Clicking on pan/zoom button:

    Press the right mouse button to zoom, dragging it to a new position. The x axis will be zoomed in proportionate to the rightward movement and zoomed out proportionate to the leftward movement.

  2. Clicking on zoom-to-rectangle button:

    Put your mouse somewhere over and axes and press the left mouse button. Drag the mouse while holding the button to a new location and release.

like image 80
Pacific Stickler Avatar answered Oct 02 '22 15:10

Pacific Stickler