8000 GitHub - PeterJust/panzoom: Intuitively pan and zoom a plot using mouse drag'n'drop and mouse-wheel in python matplotlib or MATLAB.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Intuitively pan and zoom a plot using mouse drag'n'drop and mouse-wheel in python matplotlib or MATLAB.

License

Notifications You must be signed in to change notification settings

PeterJust/panzoom

{"props":{"initialPayload":{"allShortcutsEnabled":false,"path":"/","repo":{"id":311468554,"defaultBranch":"main","name":"panzoom","ownerLogin":"PeterJust","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2020-11-09T21:23:51.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/32579272?v=4","public":true,"private":false,"isOrgOwned":false},"currentUser":null,"refInfo":{"name":"main","listCacheKey":"v0:1604957034.0","canEdit":false,"refType":"branch","currentOid":"8efc40f7a674b115dfca1f364e4d9bff42a9a62d"},"tree":{"items":[{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"panzoom.m","path":"panzoom.m","contentType":"file"},{"name":"panzoom.py","path":"panzoom.py","contentType":"file"},{"name":"zoomfunction_derivation.jpeg","path":"zoomfunction_derivation.jpeg","contentType":"file"}],"templateDirectorySuggestionUrl":null,"readme":null,"totalCount":5,"showBranchInfobar":false},"fileTree":null,"fileTreeProcessingTime":null,"foldersToFetch":[],"treeExpanded":false,"symbolsExpanded":false,"isOverview":true,"overview":{"banners":{"shouldRecommendReadme":false,"isPersonalRepo":false,"showUseActionBanner":false,"actionSlug":null,"actionId":null,"showProtectBranchBanner":false,"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_repo","releasePath":"/PeterJust/panzoom/releases/new?marketplace=true","showPublishActionBanner":false},"interactionLimitBanner":null,"showInvitationBanner":false,"inviterName":null,"actionsMigrationBannerInfo":{"releaseTags":[],"showImmutableActionsMigrationBanner":false,"initialMigrationStatus":null}},"codeButton":{"contactPath":"/contact","isEnterprise":false,"local":{"protocolInfo":{"httpAvailable":true,"sshAvailable":null,"httpUrl":"https://github.com/PeterJust/panzoom.git","showCloneWarning":null,"sshUrl":null,"sshCertificatesRequired":null,"sshCertificatesAvailable":null,"ghCliUrl":"gh repo clone PeterJust/panzoom","defaultProtocol":"http","newSshKeyUrl":"/settings/ssh/new","setProtocolPath":"/users/set_protocol"},"platformInfo":{"cloneUrl":"https://desktop.github.com","showVisualStudioCloneButton":false,"visualStudioCloneUrl":"https://windows.github.com","showXcodeCloneButton":false,"xcodeCloneUrl":"xcode://clone?repo=https%3A%2F%2Fgithub.com%2FPeterJust%2Fpanzoom","zipballUrl":"/PeterJust/panzoom/archive/refs/heads/main.zip"}},"newCodespacePath":"/codespaces/new?hide_repo_select=true\u0026repo=311468554"},"popovers":{"rename":null,"renamedParentRepo":null},"commitCount":"10","overviewFiles":[{"displayName":"README.md","repoName":"panzoom","refName":"main","path":"README.md","preferredFileType":"readme","tabName":"README","richText":"\u003carticle class=\"markdown-body entry-content container-lg\" itemprop=\"text\"\u003e\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch1 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003epanzoom.py\u003c/h1\u003e\u003ca id=\"user-content-panzoompy\" class=\"anchor\" aria-label=\"Permalink: panzoom.py\" href=\"#panzoompy\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eIntuitively pan and zoom a plot using drag-n-drop and the mouse-wheel in python matplotlib.\u003c/p\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eInstallation/Usage:\u003c/h3\u003e\u003ca id=\"user-content-installationusage\" class=\"anchor\" aria-label=\"Permalink: Installation/Usage:\" href=\"#installationusage\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003col dir=\"auto\"\u003e\n\u003cli\u003eplace panzoom.py in your python path (or os.chdir to the folder containing it before import) and import it.\u003c/li\u003e\n\u003cli\u003eInstantiate the Panzoom class, and pass the figure handle/object as first argument. It then connects to all the necessary callback functions of the figure. \u003cem\u003eOptional argument:\u003c/em\u003e base_scale = \u003cem\u003escale\u003c/em\u003e -\u0026gt; the factor by which the figure is zoomed each step.\u003c/li\u003e\n\u003cli\u003ePan by clicking and dragging. Zoom using the mouswheel. Shift key: x-axis only zoom. Control key: y-axis only zoom. Simple as that.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eExample:\u003c/h3\u003e\u003ca id=\"user-content-example\" class=\"anchor\" aria-label=\"Permalink: Example:\" href=\"#example\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"import matplotlib.pyplot as plt\nfrom panzoom import Panzoom\n\nfig1 = plt.figure()\nplt.plot([0, 1, 3, 6, 7, 4, 2, 0])\nplt.show()\npanzoomer = Panzoom(fig1)\nprint(\u0026quot;drag-n-drop panning and mouswheel zooming awesomeness. Now: at your fingertips!\u0026quot;)\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode\u003eimport matplotlib.pyplot as plt\nfrom panzoom import Panzoom\n\nfig1 = plt.figure()\nplt.plot([0, 1, 3, 6, 7, 4, 2, 0])\nplt.show()\npanzoomer = Panzoom(fig1)\nprint(\"drag-n-drop panning and mouswheel zooming awesomeness. Now: at your fingertips!\")\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eKnown Bugs:\u003c/h3\u003e\u003ca id=\"user-content-known-bugs\" class=\"anchor\" aria-label=\"Permalink: Known Bugs:\" href=\"#known-bugs\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eThe \"home\" button resetting the figure does not work properly any more after Panzoom has been applied.\u003c/p\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch1 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003epanzoom.m\u003c/h1\u003e\u003ca id=\"user-content-panzoomm\" class=\"anchor\" aria-label=\"Permalink: panzoom.m\" href=\"#panzoomm\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003ePython and Matlab seem to share clumsy plot interaction. The python class is a port of my original panzoom.m matlab function. This file is the awesome original from my graphical data segmentation software (Auswertung2) only documented in German.\nTo use this in Matlab, place panzoom.m in the same folder as your script (or use addpath).\nThen in your script go for:\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"allfigures = findall(0, 'type','figure');\nallaxes = findall(0, 'type', 'axes');\nfor ii = 1:size(allfigures, 1)\n allfigures(ii).WindowButtonMotionFcn = @panzoom;\n allfigures(ii).WindowButtonUpFcn = @panzoom;\n allfigures(ii).WindowScrollWheelFcn = @panzoom;\n allfigures(ii).WindowKeyPressFcn = @panzoom;\n allfigures(ii).WindowKeyReleaseFcn = @panzoom;\nend\nfor ii = 1:size(allaxes,1)\n allaxes(ii).ButtonDownFcn = @panzoom;\nend\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode\u003eallfigures = findall(0, 'type','figure');\nallaxes = findall(0, 'type', 'axes');\nfor ii = 1:size(allfigures, 1)\n allfigures(ii).WindowButtonMotionFcn = @panzoom;\n allfigures(ii).WindowButtonUpFcn = @panzoom;\n allfigures(ii).WindowScrollWheelFcn = @panzoom;\n allfigures(ii).WindowKeyPressFcn = @panzoom;\n allfigures(ii).WindowKeyReleaseFcn = @panzoom;\nend\nfor ii = 1:size(allaxes,1)\n allaxes(ii).ButtonDownFcn = @panzoom;\nend\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eKeys for x- and y-axis zoom are also 'ctrl' and 'shift'.\nI haven't checked if panzoom.m also works in Octave and the like. Octave is still missing some figure() functionality.\u003c/p\u003e\n\u003c/article\u003e","loaded":true,"timedOut":false,"errorMessage":null,"headerInfo":{"toc":[{"level":1,"text":"panzoom.py","anchor":"panzoompy","htmlText":"panzoom.py"},{"level":3,"text":"Installation/Usage:","anchor":"installationusage","htmlText":"Installation/Usage:"},{"level":3,"text":"Example:","anchor":"example","htmlText":"Example:"},{"level":3,"text":"Known Bugs:","anchor":"known-bugs","htmlText":"Known Bugs:"},{"level":1,"text":"panzoom.m","anchor":"panzoomm","htmlText":"panzoom.m"}],"siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2FPeterJust%2Fpanzoom"}},{"displayName":"LICENSE","repoName":"panzoom","refName":"main","path":"LICENSE","preferredFileType":"license","tabName":"GPL-3.0","richText":null,"loaded":false,"timedOut":false,"errorMessage":null,"headerInfo":{"toc":null,"siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2FPeterJust%2Fpanzoom"}}],"overviewFilesProcessingTime":0}},"appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-7d7eb7c71814.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-708ec8ade250.js","githubDevUrl":null,"enabled_features":{"copilot_workspace":null,"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true,"github_models_repo_integration":false}}}}

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

panzoom.py

Intuitively pan and zoom a plot using drag-n-drop and the mouse-wheel in python matplotlib.

Installation/Usage:

  1. place panzoom.py in your python path (or os.chdir to the folder containing it before import) and import it.
  2. Instantiate the Panzoom class, and pass the figure handle/object as first argument. It then connects to all the necessary callback functions of the figure. Optional argument: base_scale = scale -> the factor by which the figure is zoomed each step.
  3. Pan by clicking and dragging. Zoom using the mouswheel. Shift key: x-axis only zoom. Control key: y-axis only zoom. Simple as that.

Example:

import matplotlib.pyplot as plt
from panzoom import Panzoom

fig1 = plt.figure()
plt.plot([0, 1, 3, 6, 7, 4, 2, 0])
plt.show()
panzoomer = Panzoom(fig1)
print("drag-n-drop panning and mouswheel zooming awesomeness. Now: at your fingertips!")

Known Bugs:

The "home" button resetting the figure does not work properly any more after Panzoom has been applied.

panzoom.m

Python and Matlab seem to share clumsy plot interaction. The python class is a port of my original panzoom.m matlab function. This file is the awesome original from my graphical data segmentation software (Auswertung2) only documented in German. To use this in Matlab, place panzoom.m in the same folder as your script (or use addpath). Then in your script go for:

allfigures = findall(0, 'type','figure');
allaxes = findall(0, 'type', 'axes');
for ii = 1:size(allfigures, 1)
    allfigures(ii).WindowButtonMotionFcn = @panzoom;
    allfigures(ii).WindowButtonUpFcn = @panzoom;
    allfigures(ii).WindowScrollWheelFcn = @panzoom;
    allfigures(ii).WindowKeyPressFcn = @panzoom;
    allfigures(ii).WindowKeyReleaseFcn = @panzoom;
end
for ii = 1:size(allaxes,1)
    allaxes(ii).ButtonDownFcn = @panzoom;
end

Keys for x- and y-axis zoom are also 'ctrl' and 'shift'. I haven't checked if panzoom.m also works in Octave and the like. Octave is still missing some figure() functionality.

About

Intuitively pan and zoom a plot using mouse drag'n'drop and mouse-wheel in python matplotlib or MATLAB.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0