Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PGF Backend: Support interpolation='none'#6792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 4 commits intomatplotlib:masterfromf0k:pgf-transform
Aug 27, 2016
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Add more transforms to affine image transform demo
  • Loading branch information
@f0k
f0k committedAug 16, 2016
commitd931283c9adf082dc9c6ae74a9e9609f6dd306f9
49 changes: 30 additions & 19 deletionsexamples/api/demo_affine_image.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
"""
For the backends thatsupports draw_image with optional affine
For the backends thatsupport draw_image with optional affine
transform (e.g., agg, ps backend), the image of the output should
have its boundarymatches thered rectangles.
have its boundarymatch thedashed yellow rectangle.
"""

import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
Expand All@@ -21,25 +20,37 @@ def get_image():
return Z


if 1:
def do_plot(ax, Z, transform):
im = ax.imshow(Z, interpolation='none',
origin='lower',
extent=[-2, 4, -3, 2], clip_on=True)

# image rotation
trans_data = transform + ax.transData
im.set_transform(trans_data)

fig, ax1 = plt.subplots(1, 1)
Z = get_image()
im1 = ax1.imshow(Z, interpolation='none',
origin='lower',
extent=[-2, 4, -3, 2], clip_on=True)
# display intended extent of the image
x1, x2, y1, y2 = im.get_extent()
ax.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], "y--",
transform=trans_data)
ax.set_xlim(-5, 5)
ax.set_ylim(-4, 4)

trans_data2 = mtransforms.Affine2D().rotate_deg(30) + ax1.transData
im1.set_transform(trans_data2)

# display intended extent of the image
x1, x2, y1, y2 = im1.get_extent()
x3, y3 = x2, y1
# prepare image and figure
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
Z = get_image()

# image rotation
do_plot(ax1, Z, mtransforms.Affine2D().rotate_deg(30))

# image skew
do_plot(ax2, Z, mtransforms.Affine2D().skew_deg(30, 15))

# scale and reflection
do_plot(ax3, Z, mtransforms.Affine2D().scale(-1, .5))

ax1.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], "--",
transform=trans_data2)
# everything and a translation
do_plot(ax4, Z, mtransforms.Affine2D().
rotate_deg(30).skew_deg(30, 15).scale(-1, .5).translate(.5, -1))

ax1.set_xlim(-3, 5)
ax1.set_ylim(-4, 4)
plt.show()

[8]ページ先頭

©2009-2025 Movatter.jp