模型和能带, 学术

画转角石墨烯示意图(附Python代码)

如果需要严格画图,用一般的画图软件往往会引入误差。即使通过输入坐标来调整位置,也显得十分繁琐。由于转角石墨烯对画图精确度要求很高,因此这里使用Python的matplotlib来画示意图,保存eps矢量图后还可以通过AI等软件做进一步处理。

除此之外,还可以通过Pybinding等软件包进行画图。

1. 方格子

python代码:

"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""

import numpy as np


def main():
    x_array = np.arange(-5, 5.1)
    y_array = np.arange(-5, 5.1)
    coordinates = []
    for x in x_array:
        for y in y_array:
            coordinates.append([x, y])
    plot_dots(coordinates)


def plot_dots(coordinates):
    import matplotlib.pyplot as plt
    fig, ax = plt.subplots(figsize=(9,9))
    plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
    plt.axis('off')
    for i1 in range(len(coordinates)):
        for i2 in range(len(coordinates)):
            if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
                ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
    for i in range(len(coordinates)):
        ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=10)
    # plt.savefig('square.eps') 
    plt.show()


if __name__ == '__main__':
    main()

运行结果:

2. 石墨烯

python代码:

"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""

import numpy as np


def main():
    x_array = np.arange(-5, 5.1)
    y_array = np.arange(-5, 5.1)
    coordinates = []
    for x in x_array:
        for y in y_array:
            coordinates.append([0+x*3, 0+y*np.sqrt(3)])
            coordinates.append([1+x*3, 0+y*np.sqrt(3)])
            coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
            coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
    plot_dots(coordinates)


def plot_dots(coordinates):
    import matplotlib.pyplot as plt
    x_range = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
    y_range = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
    fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
    plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
    plt.axis('off')
    for i1 in range(len(coordinates)):
        for i2 in range(len(coordinates)):
            if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
                ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
    for i in range(len(coordinates)):
        ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=8)
    # plt.savefig('graphene.eps') 
    plt.show()


if __name__ == '__main__':
    main()

运行结果:

3. 转角石墨烯

python代码:

"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""

import numpy as np
import copy
import matplotlib.pyplot as plt
from math import *

def main():
    x_array = np.arange(-20, 20.1)
    y_array = np.arange(-20, 20.1)
    coordinates = []
    for x in x_array:
        for y in y_array:
            coordinates.append([0+x*3, 0+y*np.sqrt(3)])
            coordinates.append([1+x*3, 0+y*np.sqrt(3)])
            coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
            coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
    x_range1 = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
    y_range1 = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
    
    theta = -1.1/180*pi
    rotation_matrix = np.zeros((2, 2))
    rotation_matrix[0, 0] = np.cos(theta)
    rotation_matrix[1, 1] = np.cos(theta)
    rotation_matrix[0, 1] = -np.sin(theta)
    rotation_matrix[1, 0] = np.sin(theta)
    coordinates2 = copy.deepcopy(coordinates)
    for i in range(len(coordinates)):
        coordinates2[i] = np.dot(rotation_matrix, coordinates[i])
    x_range2 = max(np.array(coordinates2)[:, 0])-min(np.array(coordinates2)[:, 0])
    y_range2 = max(np.array(coordinates2)[:, 1])-min(np.array(coordinates2)[:, 1])

    x_range = max([x_range1, x_range2])
    y_range = max([y_range1, y_range2])
    fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
    plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
    plt.axis('off')
    plot_dots_1(ax, coordinates)
    plot_dots_2(ax, coordinates2)
    plot_dots_0(ax, [[0, 0]])
    plt.savefig('twist_graphene.eps') 
    plt.show()


def plot_dots_0(ax, coordinates):
    for i in range(len(coordinates)):
        ax.plot(coordinates[i][0], coordinates[i][1], 'ko', markersize=0.5)


def plot_dots_1(ax, coordinates):
    for i1 in range(len(coordinates)):
        for i2 in range(len(coordinates)):
            if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
                ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=0.2)
    for i in range(len(coordinates)):
        ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=0.5)
    

def plot_dots_2(ax, coordinates):
    for i1 in range(len(coordinates)):
        for i2 in range(len(coordinates)):
            if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
                ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '--k', linewidth=0.2)
    for i in range(len(coordinates)):
        ax.plot(coordinates[i][0], coordinates[i][1], 'bo', markersize=0.5)    


if __name__ == '__main__':
    main()

运行结果(转角1.1度):

转角21.8度的结果:

2,622 次浏览

【说明:本站主要是个人的一些笔记和代码分享,内容可能会不定期修改。为了使全网显示的始终是最新版本,这里的文章未经同意请勿转载。引用请注明出处:https://www.guanjihuan.com

评论说明:
(1)在保留浏览器缓存的前提下,目前支持72小时自主修改或删除个人评论。如果自己无法修改或删除评论,可再次评论或联系我。如有发现广告留言,请勿点击链接,博主会不定期删除。
(2)评论支持Latex公式。把latexpage作为标签放在任何位置,评论中的公式可正常编译,示例:
$Latex formula$  [latexpage]

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注