本文介绍了Pyplot:绘制一条在一侧带有刻度的曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在matplotlib.pyplot中使用plot()函数来绘制这样的在一侧具有刻度的曲线吗?:
解决方案
升级根据答案
可以使用 marker_every 控制标记的密度.
Can I use the plot() function in matplotlib.pyplot to plot curves like this which have ticks on one side?:
解决方案
UpgradeBased on the answer here I could extend the example:
def f(x): return x, x * np.exp(-x*x)
def get_parameters(x,y):
xp = 0.5*(x[1:nx] + x[0:nx-1]) # the points between
yp = 0.5*(y[1:nx] + y[0:nx-1])
dy = np.diff(y); dx = np.diff(x) # the gradient
nn = 40*np.sqrt(dx*dx + dy*dy) # nn=norm; 40 = empirical hack for the normal shift
dx = dx/nn; dy = dy/nn # the components of the normals
alpha = 180*np.arctan(dy/dx)/np.pi # the slope angel to the normal
return xp,yp,dx,dy,alpha
nx = 20;
ip = np.linspace(0,1,nx)
xr,yr = f(3*ip-0.5) # red front line
xb,yb = f(3*ip-0.5); yb = 0.7*yb -0.3 # blue front line
xpb, ypb, dx, dy, alphaB = get_parameters(xb,yb) # red points between
xpr, ypr, _, _, alphaR = get_parameters(xr,yr) # blue points between
plt.style.use('fast')
fig, ax0 = plt.subplots(figsize=(20,20))
plt.plot(xr,yr, c='r', lw=5, label='warm front')
plt.plot(xb,yb, c='b', lw=5, label='cold front')
for j in range(nx-1):
#--- set the blue markers ---
marker_size_B = 900
plt.scatter(xpb[j]-dy[j], ypb[j]+dx[j],
s=marker_size_B, c='b', marker=(3, 0, alphaB[j]) )
#--- set the red markers ---
marker_size_R=0.05
halfR = mpl.patches.Wedge((xpr[j], ypr[j]), marker_size_R, theta1=0+alphaB[j], theta2=180+alphaB[j], color='r')
ax0.add_artist(halfR)
plt.legend(prop={'size': 20})
ax0.set_aspect('equal'); plt.grid(); plt.margins(0.1);plt.show()
The densitiy of the markers can be controlled with marker_every.
这篇关于Pyplot:绘制一条在一侧带有刻度的曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!