Python matplotlib显示子批次对象中的单个图形
我有18个数据集,我已经使用plt.subplot显示了所有18个图形,如下所示Python matplotlib显示子批次对象中的单个图形,python,matplotlib,subplot,Python,Matplotlib,Subplot,我有18个数据集,我已经使用plt.subplot显示了所有18个图形,如下所示 import matplotlib.pyplot as plt f,ax_array=plt.subplots(6,3) for i in range(0,6): for j in range(0,3): ax_array[i][j].plot(modified_data[3*i+j]) plt.show() #modified data is my data set 我想做的是显示一个
import matplotlib.pyplot as plt
f,ax_array=plt.subplots(6,3)
for i in range(0,6):
for j in range(0,3):
ax_array[i][j].plot(modified_data[3*i+j])
plt.show()
#modified data is my data set
我想做的是显示一个图表。例如,如何显示与ax_array[3][2]相对应的图形?结果并非如此简单,最简单的解决方案是创建一个新图形,然后再次使用所需数据发出plot命令。跨多个图形共享轴对象是相当困难的 但是,下面的解决方案允许您使用shift+左键单击放大特定子批次
def add_subplot_zoom(figure):
zoomed_axes = [None]
def on_click(event):
ax = event.inaxes
if ax is None:
# occurs when a region not in an axis is clicked...
return
# we want to allow other navigation modes as well. Only act in case
# shift was pressed and the correct mouse button was used
if event.key != 'shift' or event.button != 1:
return
if zoomed_axes[0] is None:
# not zoomed so far. Perform zoom
# store the original position of the axes
zoomed_axes[0] = (ax, ax.get_position())
ax.set_position([0.1, 0.1, 0.85, 0.85])
# hide all the other axes...
for axis in event.canvas.figure.axes:
if axis is not ax:
axis.set_visible(False)
else:
# restore the original state
zoomed_axes[0][0].set_position(zoomed_axes[0][1])
zoomed_axes[0] = None
# make other axes visible again
for axis in event.canvas.figure.axes:
axis.set_visible(True)
# redraw to make changes visible.
event.canvas.draw()
figure.canvas.mpl_connect('button_press_event', on_click)
。将示例中的函数调用为:
import matplotlib.pyplot as plt
f,ax_array=plt.subplots(6,3)
for i in range(0,6):
for j in range(0,3):
ax_array[i][j].plot(modified_data[3*i+j])
add_subplot_zoom(f)
plt.show()