该图显示了模拟神经元的电压路线:
我想在右上角放置一个放大图,以便您可以更好地看到线条当前的波动(这里的比例使得您几乎看不到它们)
附上绘图代码
factor to define voltage-amplitude heightsv_amp_factor = 1/(50) ##### distances between lines and x-axis offset = np.cumsum(distance_comps_middle)/meter offset = (offset/max(offset))*10 plt.close(plot_name) voltage_course = plt.figure(plot_name) for ii in comps_to_plot: plt.plot(time_vector/ms, offset[ii] - v_amp_factor*(voltage_matrix[ii, :]-V_res)/mV, "#000000") plt.yticks(np.linspace(0,10, int(length_neuron/mm)+1),range(0,int(length_neuron/mm)+1,1)) plt.xlabel('Time/ms', fontsize=16) plt.gca().invert_yaxis() # inverts y-axis => - v_amp_factor*(.... has to be written above ##### no grid plt.grid(False) plt.savefig('plot_name', dpi=600) plt.show(plot_name)
parameter description:
Parameters
----------
plot_name : string
This defines how the plot window will be named.
time_vector : list of time values
Vector contains the time points, that correspond to the voltage values
of the voltage matrix.
voltage_matrix : matrix of membrane potentials
Matrix has one row for each compartment and one columns for each time
step. Number of columns has to be the same as the length of the time vector
comps_to_plot : vector of integers
This vector includes the numbers of the compartments, which should be part of the plot.
distance_comps_middle : list of lengths
This list contains the distances of the compartments, which allows that
the lines in the plot are spaced according to the real compartment distances
length_neuron : length
Defines the total length of the neuron.
V_res : voltage
Defines the resting potential of the model.
最佳答案
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
# let's plot something similar to your stuff
t = np.linspace(-5, 5, 2001)
y = np.exp(-20*t**2)
fig, ax = plt.subplots()
for i in range(14):
start = 900-10*i
ax.plot(t[1000:1500], -5*y[start:start+500]/(1+i*0.3)+i, 'k')
ax.set_ylim((15, -10)) ; ax.set_yticks(range(14))
# now, create an inset axis, in the upper right corner, with
# a zoom factor of two
zax = zoomed_inset_axes(ax, 2, loc=1)
# plot again (PLOT AGAIN) the same stuff as before in the new axes
for i in range(14):
start = 900-10*i
zax.plot(t[1000:1500], -5*y[start:start+500]/(1+i*0.3)+i, 'k')
# and eventually specify the x, y limits for the zoomed plot,
# as well as the tick positions
zax.set_xlim((0.2, 0.7)) ; zax.set_xticks((0.2, 0.3, 0.4, 0.5, 0.6, 0.7))
zax.set_ylim((1, -6)) ; zax.set_yticks([1]+[-i*0.5 for i in range(12)]) ;
# that's all folks
plt.show()
关于python - 如何放大绘图内部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64405959/