Show Diameter
Posted: Wed Mar 27, 2024 9:23 am
The code below is plotting the membrane potential of the entire neuron via PlotShape, but I want to show the diameter of the neuron. When I set ps.show(1) as suggested by the document, it doesn't successfully show the diameter of the neuron.
Is there any solution to make plotshape in neuron python display the radius of the neuron?
Is there any solution to make plotshape in neuron python display the radius of the neuron?
Code: Select all
v_vals = [seg.v for sec in h.allsec() for seg in sec]
print(min(v_vals),max(v_vals))
if setv:
minv= vmin
maxv = vmax
else:
minv= min(v_vals)
maxv= max(v_vals)
ps = h.PlotShape(False) # False tells h.PlotShape not to use NEURON's gui
ps.variable('v')
ps.scale(minv, maxv)
ax = ps.plot(pyplot, cmap=cmap)
ps.show(1)
# 设置坐标轴范围
ax.set_xlim([-700, 0]) # 替换 xmin 和 xmax 为所需的 x 范围
ax.set_ylim([500, 1400]) # 替换 ymin 和 ymax 为所需的 y 范围
ax.set_zlim([-1000, 00]) # 替换 zmin 和 zmax 为所需的 z 范围
# 关闭网格
ax.grid(False)
# 关闭坐标轴
ax.axis('off')
# 保存为 EPS 格式
if savefig:
plt.savefig(figname+'.eps', format='eps')
# second figure
ps = h.PlotShape(True)
ps.variable("v")
ps.scale(minv, maxv)
fig = ps.plot(plotly, cmap=cmap)
# Create a colormap function
colormap = cm.ScalarMappable(cmap=cmap,
norm=mcolors.Normalize(vmin=0, vmax=1)).to_rgba
# Map the normalized values to a Plotly colorscale as strings
plotly_colorscale = [[v, f'rgb{tuple(int(255 * c) for c in colormap(v)[:3])}'] for v in np.linspace(0, 1, cmap.N)]
# Create a separate scatter plot for the colorbar
colorbar_trace = go.Scatter(
x=[0],
y=[0],
mode='markers',
marker=dict(
colorscale=plotly_colorscale,
cmin=minv,
cmax=maxv,
colorbar=dict(
title=colorbarlabel,
thickness=20 # Adjust the thickness of the colorbar
),
showscale=True
)
)
# Add the colorbar trace to the figure
fig.add_trace(colorbar_trace)
fig.update_xaxes(showticklabels=False, showgrid=True)
fig.update_yaxes(showticklabels=False, showgrid=True)
fig.update_layout(
plot_bgcolor='rgba(0,0,0,0)'
)
fig.show()
if savefig:
# 保存动图为 HTML 文件
plotly.offline.plot(fig, filename=figname+'.html', auto_open=False)
# 创建自定义的颜色映射
cmap = cmap
colormap = cm.ScalarMappable(cmap=cmap,
norm=mcolors.Normalize(vmin=minv, vmax=maxv))
# 创建一个新的图形和轴
fig, ax = plt.subplots(figsize=(6, 1))
# 绘制颜色条
cbar = plt.colorbar(colormap, cax=ax, orientation='horizontal')
cbar.set_label(colorbarlabel)
if ticklabels:
cbar.set_ticks(np.arange(tickmin, tickmax, dt))
cbar.set_ticklabels([f'{i}' for i in np.arange(tickmin, tickmax, dt)])
# 设置图的边界
plt.tight_layout()
if savefig:
# 保存为 EPS 格式
plt.savefig(figname+'colorbar'+'.eps', format='eps')
# 显示图形(可选)
plt.show()