PyPlot.plot will give the incorrect number

Hello
I felt confusing, when I use pyplot.plt. The data in figure is different from the printed.
There are the codes:
# ================================================================
# Physics background
# ------------------
# Kwant features highlighted
# --------------------------
# - Numpy matrices as values in Builder
import kwant
import numpy as np
# For plotting
import matplotlib.pyplot as plt
# For matrix support
import tinyarray
import kwant.qsymm
# define Pauli-matrices for convenience
s_0 = tinyarray.array([[1, 0], [0, 1]])
s_x = tinyarray.array([[0, 1], [1, 0]])
s_y = tinyarray.array([[0, -1j], [1j, 0]])
s_z = tinyarray.array([[1, 0], [0, -1]])
mz=0 # AFM
mu=0.0 # stargged chemical potential
n_theta=12
def make_system(constant=1, W=30, L=30, mz=0, m_in=0, mu=0):
lat = kwant.lattice.honeycomb(a=constant,norbs=2, name=['a', 'b'])
# a, b = lat.sublattices
sym = kwant.TranslationalSymmetry(lat.vec((1, 0)))
syst = kwant.Builder()
def onsite_a(site,theta):
return mz*s_z+m_in*(np.cos(theta)*s_x+np.sin(theta)*s_y)+mu*s_0
def onsite_b(site,theta):
return -mz*s_z+m_in*(np.cos(theta)*s_x+np.sin(theta)*s_y)-mu*s_0
syst[(lat.a(x, y) for x in range(L) for y in range(W))] = onsite_a
syst[(lat.b(x, y) for x in range(L) for y in range(W))] = onsite_b
syst[lat.neighbors()] = s_0
# define lead
left_sym=kwant.TranslationalSymmetry(lat.vec((1, 0)))
left_lead=kwant.Builder(left_sym)
left_lead[(lat.a(0, y) for y in range(W))] = onsite_a
left_lead[(lat.b(0, y) for y in range(W))] = onsite_b
left_lead[lat.neighbors()] = s_0
syst.attach_lead(left_lead)
syst.attach_lead(left_lead.reversed())
return syst
def plot_conductance(syst, energy, theta_list):
# Compute conductance
data = np.zeros(n_theta)
num_i=-1
for theta_i in theta_list:
num_i=num_i+1
smatrix = kwant.smatrix(syst, energy, params=dict(theta=theta_i))
data[num_i]=smatrix.transmission(1, 0)
plt.figure()
# x=np.linspace(-1,1,n_theta)
# data_i=np.linspace(0,0,n_theta)
# print(x,data_i)
# plt.plot(x,data_i,'ow')
print(data)
plt.plot(theta_list, data)
plt.xlabel(r'$\theta/\pi$')
plt.ylabel("conductance [e^2/h]")
plt.savefig('tran_PHE.jpg')
#plt.show()
def main():
syst = make_system(m_in=0.0001)
# Check that the system looks as intended.
kwant.plot(syst,file='transport_lattice.pdf')
syst = syst.finalized()
theta_num=np.linspace(-np.pi,np.pi,num=n_theta)
plot_conductance(syst, energy=0.0001,
theta_list=theta_num)
if __name__ == '__main__':
main()
The result would be printed in terminal: [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.].
However, the figure plotted is wrong.
--
Best Wishes Jinlong Zhang jlzhang@163.com

Dear 张金龙,
Note the axis of the plot reads 1e-9+1, so the plot limits go from 1 - 0.2e-9 to 1 + 1e-9. This how matplotlib treats plots that are approximately constant.
Hope this helps, Anton
On Sat, 15 May 2021 at 13:24, 张金龙 jlzhang1996@163.com wrote:
Hello
I felt confusing, when I use pyplot.plt. The data in figure is different from the printed.
There are the codes:
# ================================================================
# Physics background
# ------------------
# Kwant features highlighted
# --------------------------
# - Numpy matrices as values in Builder
import kwant
import numpy as np
# For plotting
import matplotlib.pyplot as plt
# For matrix support
import tinyarray
import kwant.qsymm
# define Pauli-matrices for convenience
s_0 = tinyarray.array([[1, 0], [0, 1]])
s_x = tinyarray.array([[0, 1], [1, 0]])
s_y = tinyarray.array([[0, -1j], [1j, 0]])
s_z = tinyarray.array([[1, 0], [0, -1]])
mz=0 # AFM
mu=0.0 # stargged chemical potential
n_theta=12
def make_system(constant=1, W=30, L=30, mz=0, m_in=0, mu=0):
lat = kwant.lattice.honeycomb(a=constant,norbs=2, name=['a', 'b']) # a, b = lat.sublattices sym = kwant.TranslationalSymmetry(lat.vec((1, 0))) syst = kwant.Builder() def onsite_a(site,theta): return mz*s_z+m_in*(np.cos(theta)*s_x+np.sin(theta)*s_y)+mu*s_0 def onsite_b(site,theta): return -mz*s_z+m_in*(np.cos(theta)*s_x+np.sin(theta)*s_y)-mu*s_0 syst[(lat.a(x, y) for x in range(L) for y in range(W))] = onsite_a syst[(lat.b(x, y) for x in range(L) for y in range(W))] = onsite_b syst[lat.neighbors()] = s_0 # define lead left_sym=kwant.TranslationalSymmetry(lat.vec((1, 0))) left_lead=kwant.Builder(left_sym) left_lead[(lat.a(0, y) for y in range(W))] = onsite_a left_lead[(lat.b(0, y) for y in range(W))] = onsite_b left_lead[lat.neighbors()] = s_0 syst.attach_lead(left_lead) syst.attach_lead(left_lead.reversed()) return syst
def plot_conductance(syst, energy, theta_list):
# Compute conductance data = np.zeros(n_theta) num_i=-1 for theta_i in theta_list: num_i=num_i+1 smatrix = kwant.smatrix(syst, energy, params=dict(theta=theta_i)) data[num_i]=smatrix.transmission(1, 0) plt.figure() # x=np.linspace(-1,1,n_theta) # data_i=np.linspace(0,0,n_theta) # print(x,data_i) # plt.plot(x,data_i,'ow') print(data) plt.plot(theta_list, data) plt.xlabel(r'$\theta/\pi$') plt.ylabel("conductance [e^2/h]") plt.savefig('tran_PHE.jpg') #plt.show()
def main():
syst = make_system(m_in=0.0001) # Check that the system looks as intended. kwant.plot(syst,file='transport_lattice.pdf') syst = syst.finalized() theta_num=np.linspace(-np.pi,np.pi,num=n_theta) plot_conductance(syst, energy=0.0001, theta_list=theta_num)
if __name__ == '__main__':
main()
The result would be printed in terminal: [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.].
However, the figure plotted is wrong.
--
Best Wishes Jinlong Zhang jlzhang@163.com

On Sat, May 15, 2021 at 7:27 PM Anton Akhmerov anton.akhmerov+kd@gmail.com wrote:
Dear 张金龙,
Note the axis of the plot reads 1e-9+1, so the plot limits go from 1 - 0.2e-9 to 1 + 1e-9.
I still can't figure out the following correspondence:
1e-9+1 <---> 1 - 0.2e-9 to 1 + 1e-9.
Any more hints?
HY
This how matplotlib treats plots that are approximately constant.
Hope this helps, Anton
On Sat, 15 May 2021 at 13:24, 张金龙 jlzhang1996@163.com wrote:
Hello
I felt confusing, when I use pyplot.plt. The data in figure is different from the printed.
There are the codes:
# ================================================================
# Physics background
# ------------------
# Kwant features highlighted
# --------------------------
# - Numpy matrices as values in Builder
import kwant
import numpy as np
# For plotting
import matplotlib.pyplot as plt
# For matrix support
import tinyarray
import kwant.qsymm
# define Pauli-matrices for convenience
s_0 = tinyarray.array([[1, 0], [0, 1]])
s_x = tinyarray.array([[0, 1], [1, 0]])
s_y = tinyarray.array([[0, -1j], [1j, 0]])
s_z = tinyarray.array([[1, 0], [0, -1]])
mz=0 # AFM
mu=0.0 # stargged chemical potential
n_theta=12
def make_system(constant=1, W=30, L=30, mz=0, m_in=0, mu=0):
lat = kwant.lattice.honeycomb(a=constant,norbs=2, name=['a', 'b']) # a, b = lat.sublattices sym = kwant.TranslationalSymmetry(lat.vec((1, 0))) syst = kwant.Builder() def onsite_a(site,theta): return mz*s_z+m_in*(np.cos(theta)*s_x+np.sin(theta)*s_y)+mu*s_0 def onsite_b(site,theta): return -mz*s_z+m_in*(np.cos(theta)*s_x+np.sin(theta)*s_y)-mu*s_0 syst[(lat.a(x, y) for x in range(L) for y in range(W))] = onsite_a syst[(lat.b(x, y) for x in range(L) for y in range(W))] = onsite_b syst[lat.neighbors()] = s_0 # define lead left_sym=kwant.TranslationalSymmetry(lat.vec((1, 0))) left_lead=kwant.Builder(left_sym) left_lead[(lat.a(0, y) for y in range(W))] = onsite_a left_lead[(lat.b(0, y) for y in range(W))] = onsite_b left_lead[lat.neighbors()] = s_0 syst.attach_lead(left_lead) syst.attach_lead(left_lead.reversed()) return syst
def plot_conductance(syst, energy, theta_list):
# Compute conductance data = np.zeros(n_theta) num_i=-1 for theta_i in theta_list: num_i=num_i+1 smatrix = kwant.smatrix(syst, energy, params=dict(theta=theta_i)) data[num_i]=smatrix.transmission(1, 0) plt.figure() # x=np.linspace(-1,1,n_theta) # data_i=np.linspace(0,0,n_theta) # print(x,data_i) # plt.plot(x,data_i,'ow') print(data) plt.plot(theta_list, data) plt.xlabel(r'$\theta/\pi$') plt.ylabel("conductance [e^2/h]") plt.savefig('tran_PHE.jpg') #plt.show()
def main():
syst = make_system(m_in=0.0001) # Check that the system looks as intended. kwant.plot(syst,file='transport_lattice.pdf') syst = syst.finalized() theta_num=np.linspace(-np.pi,np.pi,num=n_theta) plot_conductance(syst, energy=0.0001, theta_list=theta_num)
if __name__ == '__main__':
main()
The result would be printed in terminal: [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.].
However, the figure plotted is wrong.
--
Best Wishes Jinlong Zhang jlzhang@163.com

Thank you for your answer. I think that it is the default option in matplotlib.pyplot, but I'm not used to this label.
The plot ylimits go from 1e-8+1 to 9e-8+1. However, the scale of y-axis is 1、2、3、4、5、6、7、8、9, meanwhile label the 1e-8+1 in the top over y-axis.
So I felt confusing whether the data is 1e-8+1、2e-8+2、3e-8+3、4e-8+4、...9e-8+9 or 1e-8+1、2e-8+1、3e-8+1、4e-8+1、...9e-8+1.
With the suggestion of Pr. Anton Akhmerov, I try this codes:
####################### import numpy as np import matplotlib.pyplot as plt
y=1+np.linspace(1,9,100)*1e-8 x=np.linspace(1,9,100) plt.plot(x,y) plt.show() #######################
The latter one is correct: 1e-8+1、2e-8+1、3e-8+1、4e-8+1、...9e-8+1.
Sorry about that I don't know how to attach the figure in the community.
jinlong zhang

Thank you for your answer.
I think that it is the default option in matplotlib.pyplot, but I'm not used to this label.
The plot ylimits go from 1e-8+1 to 9e-8+1. However, the scale of y-axis is 1、2、3、4、5、6、7、8、9, meanwhile label the 1e-8+1 in the top over y-axis.
So I felt confusing whether the data is 1e-8+1、2e-8+2、3e-8+3、4e-8+4、...9e-8+9 or 1e-8+1、2e-8+1、3e-8+1、4e-8+1、...9e-8+1.
With the suggestion of Pr. Anton Akhmerov, I try this codes:
#######################
import numpy as np
import matplotlib.pyplot as plt
y=1+np.linspace(1,9,100)*1e-8
x=np.linspace(1,9,100)
plt.plot(x,y)
plt.show()
#######################
The latter one is correct: 1e-8+1、2e-8+1、3e-8+1、4e-8+1、...9e-8+1.
Sorry about that I don't know how to attach the pic in the community.
jinlong zhang
participants (4)
-
Anton Akhmerov
-
Hongyi Zhao
-
jlzhang1996@163.com
-
张金龙