python - matplotlib:使用标记时丑陋的情节

标签 python matplotlib

我有个小问题。我有一个程序可以为势能绘制波函数,当我在绘图中使用选项(使用 pylab)'-' 时它看起来很好,例如:http://img41.imageshack.us/img41/8798/59138635.png

如果我使用“o”我会得到: http://img16.imageshack.us/img16/3741/22378006.png

你看它看起来很丑:\

是否有一种简单的方法可以使圆圈之间的间距更大,或者这取决于代码的细节?

代码是:

from math import *
from scipy.special import *
from pylab import *
from scipy.linalg import *

firebrick=(178./255.,34./255.,34./255.)
indianred=(176./255.,23./255.,31./255.)
steelblue=(70./255.,130./255.,180./255.)
slategray1=(198./255.,226./255.,255./255.)
slategray4=(108./255.,123./255.,139./255.)
lavender=(230./255.,230./255.,230./255.)
cobalt=(61./255.,89./255.,171./255.)
midnightblue=(25./255.,25./255.,112./255.)
forestgreen=(34./255.,139./255.,34./255.)

#grid
Nmesh=512
L=4.0
dx=L/Nmesh
Xmax=L
x=arange(-L,L+0.0001,dx)
Npts=len(x)
numwav=2   #number of wave function that is being drawn

V=zeros([Npts],float)
for i in range(Npts):
    V[i]=x[i]**4

a=zeros([2,Npts-2],float)
wave=zeros([Npts],float)

wave1=zeros([Npts],float)
encor=3.0/4*(3.0/4)**(1.0/3)

#numerical solution
for i in range(1,Npts-1,1):
    a[0,i-1]= 1.0/dx**2+V[i]     #diagonal elements
    a[1,i-1]=-1.0/dx**2/2        #the elements below the diagonal
a[1,Npts-3]=-99.0                #element is not used
eig,vec=eig_banded(a,lower=1)    #routine that diagonalizes the tridiagonal matrix

for i in range(1,Npts-1,1):
    wave[i]=vec[i-1,numwav]
wave[0]=0.0             #wave function has the value zero on the first point on the grid
wave[Npts-1]=0.0        #wave function has the value zero on the last point on the grid

wave=150*wave+eig[numwav]

#potential graph
line=plt.plot(x,V)
plt.setp(line,color='firebrick',linewidth=2)

#plot of the selected level and wave function
plt.axhline(y=eig[numwav],linewidth=2,color='steelblue')

#plot of the points of the wave function
plt.plot(x,wave,"b-",linewidth=2,color='forestgreen')

plt.xlabel('x',size=16)
plt.ylabel('V(x)',size=16)
plt.axis([-4.0,4.0,-5.0,16.0]) #x and y axes range
plt.grid(True)
plt.show()

最佳答案

在进一步调查之后,我有一个更好(但不同)的答案。 Matplotlib 提供了一个 markevery 关键字,允许在放置标记方面取得进展。所以我建议,如果你想要 20 个左右的能见度点,在绿线之上:

stride = max( int(len(x) / 20), 1)
plt.plot(x,wave,"-o",color='forestgreen', markevery=stride)

如果您只需要标记,我之前的答案就可以正常工作,但如果您同时需要线条和标记,则效果会更好。

关于python - matplotlib:使用标记时丑陋的情节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5318639/

相关文章:

python - GeoPandas 绘图功能不起作用

python - 当拉docker镜像并在我自己的镜像中使用它时-它停在最后一行吗?

python - 如何检查对象是否是新型用户定义类的实例?

python - matplotlib 中的球面坐标图

python - 如何获取django项目的项目根目录

python - 以编程方式在嵌入式 python 3 中定义包结构

python - matplotlib 修改 colormap 以白色为零

python - Matplotlib 限制从 CSV 绘制的行

python matplotlib gridspec,不需要的任意轴标签

python - 向图像添加图例(如 matplotlib 图例)