Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zoomed_inset_axes shows a incorrect result. #3460

Closed
ScottZhangLiwen opened this issue Sep 3, 2014 · 2 comments
Closed

zoomed_inset_axes shows a incorrect result. #3460

ScottZhangLiwen opened this issue Sep 3, 2014 · 2 comments

Comments

@ScottZhangLiwen
Copy link

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset

ax = plt.subplot(111)
ax.set_xlim(0,100)
ax.set_ylim(0,100)

x = np.arange(0, 100, 0.1)
y = x
X, Y = np.meshgrid(x, y)

Z = X*Y -X -Y

plt.contour(X, Y, Z)

axins = zoomed_inset_axes(ax, 2.5, loc=1)
axins.set_xlim(30, 40)
axins.set_ylim(35, 45)
mark_inset(ax, axins, loc1=2, loc2=4, fc='none')
plt.xticks(visible=False)
plt.yticks(visible=False)

plt.show()

Run this code and got a image witch the contour showed correctly but zoomed axes were empty. However, I changed the order of code like:

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset

ax = plt.subplot(111)
ax.set_xlim(0,100)
ax.set_ylim(0,100)

x = np.arange(0, 100, 0.1)
y = x
X, Y = np.meshgrid(x, y)

Z = X*Y -X -Y

axins = zoomed_inset_axes(ax, 2.5, loc=1)
axins.set_xlim(30, 40)
axins.set_ylim(35, 45)
mark_inset(ax, axins, loc1=2, loc2=4, fc='none')
plt.xticks(visible=False)
plt.yticks(visible=False)

plt.contour(X, Y, Z)

plt.show()

Then I got a contour empty but zoomed axes showed correctly image.
Is this a defect of zoomed_inset_axes?

@cimarronm
Copy link
Contributor

I believe this is what you want. Note that the inset axes is just an axes so you must plot something on it (for a zoom operation it naturally is the same thing you plotted in the regular axes).

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset

ax = plt.subplot(111)
ax.set_xlim(0,100)
ax.set_ylim(0,100)

x = np.arange(0, 100, 0.1)
y = x
X, Y = np.meshgrid(x, y)

Z = X*Y -X -Y

ax.contour(X, Y, Z)

axins = zoomed_inset_axes(ax, 2.5, loc=1)
axins.contour(X, Y, Z)
axins.set_xlim(30, 40)
axins.set_ylim(35, 45)
mark_inset(ax, axins, loc1=2, loc2=4, fc='none')
plt.xticks(visible=False)
plt.yticks(visible=False)

plt.show()

@ScottZhangLiwen
Copy link
Author

Thanks very much! It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants