我想放大,例如,情節的中心部分,但我有一些問題。 我想做這樣的事情,但只能用簡單的線條。我怎樣才能做到這一點? 我有這樣一段代碼:如何放大Matplolib的一部分繪圖
import matplotlib.pyplot as plt
import pickle
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
import numpy as np
fig, ax = plt.subplots(figsize=[5,4])
extent = (0, 100, 0, 50)
xx = np.linspace(0, 100, 1000)
Z2 = [np.sin(x) for x in xx]
ax.imshow(Z2, extent=extent, interpolation="nearest",
origin="lower")
axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6
mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5")
plt.draw()
plt.show()
Python的說:
/usr/bin/python2.7 "/home/kenenbek/Documents/Pycharm Projects/PycharmProjects/Multi-Agent/vizualization.py"
/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
Traceback (most recent call last):
File "/home/kenenbek/Documents/Pycharm Projects/PycharmProjects/Multi-Agent/vizualization.py", line 55, in <module>
origin="lower")
File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1812, in inner
return func(ax, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 4947, in imshow
im.set_data(X)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/image.py", line 449, in set_data
raise TypeError("Image data can not convert to float")
TypeError: Image data can not convert to float