Untitled

 avatar
unknown
python
a year ago
2.3 kB
5
Indexable
def Vertical_line(ds_dinh, line3_x_start, line3_x_end, line3_y, line4_y):
  X0 = line3_x_end - 0.5
  ver_line_start, ver_line_end =  line3_y - 0.1 , line4_y +0.1
  for dinh in ds_dinh:
    plt.plot([X0, X0], [ver_line_start, ver_line_end], color='black')
    #Tên đường thẳng
    plt.text(X0 +0.01 , ver_line_end, dinh, fontsize=12, verticalalignment='bottom', horizontalalignment='right')

    #SD khi giao line3
    plt.text(X0 - 0.1, line3_y-0.08, 'S', fontsize=12, verticalalignment='bottom', horizontalalignment='right')

    plt.text(X0 + 0.16, line3_y-0.08, 'D', fontsize=12, verticalalignment='bottom', horizontalalignment='right')

    #SD khi giao line4
    plt.text(X0 - 0.1, line4_y+0.02, 'S', fontsize=12, verticalalignment='bottom', horizontalalignment='right')
    plt.text(X0 + 0.16, line4_y+0.02, 'D', fontsize=12, verticalalignment='bottom', horizontalalignment='right')
    X0 -= 1.2

import matplotlib.pyplot as plt

names = ["A", "B", "G", "H", "L"]
plt.figure(figsize=(8 + len(names)*0.3, 5 + len(names)*0.1)) 

# line template [x_start, x_end] [y_start, y_end]
line1_x, line1_y = [5- len(names)*1.5 , 5 ], [1, 1]
line2_x, line2_y = [5- len(names)*1.5 , 5 ], [2, 2]

line3_x, line3_y = [line1_x[0]+0.5, line1_x[1]-0.5], [1.25, 1.25]
line4_x, line4_y = [line1_x[0]+0.5, line1_x[1]-0.5], [1.75, 1.75]

plt.plot(line1_x, line1_y, line2_x, line2_y, line3_x, line3_y, line4_x, line4_y)

# Thêm nhãn "GND" trên Line1
plt.text(line1_x[1] + 0.2, line1_y[0], 'GND', fontsize=12, verticalalignment='bottom')            # distance_from_line1 = 0.1

# Thêm nhãn "VCC" kế bên Line2
plt.text(line2_x[1] + 0.2, line2_y[0], 'VCC', fontsize=12, verticalalignment='bottom')            # distance_from_line2 = 0.1

# Thêm nhãn "p diffusion" kế bên Line3
plt.text(line3_x[1] + 0.7, line3_y[0], 'n diffusion', fontsize=12, verticalalignment='bottom', horizontalalignment='right')

# Thêm nhãn "n diffusion" kế bên Line4
plt.text(line4_x[1]+ 0.7, line4_y[0], 'p diffusion', fontsize=12, verticalalignment='bottom', horizontalalignment='right')


plt.axis('off')
#print(line1_x[0], line1_x[1])
Vertical_line(names, line3_x[0], line3_x[1], line3_y[0], line4_y[0]) 
 
plt.show() 
Editor is loading...
Leave a Comment