!pip install matplotlib import matplotlib.pyplot as plt from matplotlib.patches import Rectangle fig, ax = plt.subplots(figsize=(8, 6)) ax.set_xlim(0, 10) ax.set_ylim(0, 10) ax.axis('off') # UE端发起释放EPS承载 rect_ue = Rectangle((1, 9), 2, 1, linewidth=1, edgecolor='black', facecolor='white') ax.add_patch(rect_ue) ax.text(1.5, 9.5, 'UE\nRelease\nEPS\nBearer', ha='center', va='center') # RRC连接释放 rect_rrc = Rectangle((4, 9), 2, 1, linewidth=1, edgecolor='black', facecolor='white') ax.add_patch(rect_rrc) ax.text(4.5, 9.5, 'RRC\nConnection\nRelease', ha='center', va='center') # Detach请求 rect_detach = Rectangle((7, 9), 2, 1, linewidth=1, edgecolor='black', facecolor='white') ax.add_patch(rect_detach) ax.text(8, 9.5, 'Detach\nRequest', ha='center', va='center') # 信令Attach success/connection success等信令 rect_attach = Rectangle((1, 5), 2, 1, linewidth=1, edgecolor='black', facecolor='white') ax.add_patch(rect_attach) ax.text(1.5, 5.5, 'Attach\nSuccess', ha='center', va='center') rect_conn = Rectangle((4, 5), 2, 1, linewidth=1, edgecolor='black', facecolor='white') ax.add_patch(rect_conn) ax.text(4.5, 5.5, 'Connection\nSuccess', ha='center', va='center') # 释放EPS承载完成 rect_done = Rectangle((7, 5), 2, 1, linewidth=1, edgecolor='black', facecolor='white') ax.add_patch(rect_done) ax.text(8, 5.5, 'Release\nDone', ha='center', va='center') # UE端发起释放EPS承载 -> RRC连接释放 ax.annotate('', xy=(3, 9.5), xytext=(4, 9.5), arrowprops=dict(arrowstyle='->')) # RRC连接释放 -> Detach请求 ax.annotate('', xy=(6, 9.5), xytext=(7, 9.5), arrowprops=dict(arrowstyle='->')) # Detach请求 -> 信令Attach success/connection success等信令 ax.annotate('', xy=(1, 8), xytext=(1, 5.5), arrowprops=dict(arrowstyle='->')) ax.annotate('', xy=(4, 8), xytext=(4, 5.5), arrowprops=dict(arrowstyle='->')) # 信令Attach success/connection success等信令 -> 释放EPS承载完成 ax.annotate('', xy=(3, 5.5), xytext=(7, 5.5), arrowprops=dict(arrowstyle='->')) plt.show(),这段代码画出来的图比例不太对,请调整
时间: 2023-06-17 17:05:23 浏览: 54
可以尝试添加以下代码调整图像大小比例:
```
fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
```
完整代码如下:
```
!pip install matplotlib
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
fig, ax = plt.subplots(figsize=(8, 6))
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.axis('off')
# UE端发起释放EPS承载
rect_ue = Rectangle((1, 9), 2, 1, linewidth=1, edgecolor='black', facecolor='white')
ax.add_patch(rect_ue)
ax.text(1.5, 9.5, 'UE\nRelease\nEPS\nBearer', ha='center', va='center')
# RRC连接释放
rect_rrc = Rectangle((4, 9), 2, 1, linewidth=1, edgecolor='black', facecolor='white')
ax.add_patch(rect_rrc)
ax.text(4.5, 9.5, 'RRC\nConnection\nRelease', ha='center', va='center')
# Detach请求
rect_detach = Rectangle((7, 9), 2, 1, linewidth=1, edgecolor='black', facecolor='white')
ax.add_patch(rect_detach)
ax.text(8, 9.5, 'Detach\nRequest', ha='center', va='center')
# 信令Attach success/connection success等信令
rect_attach = Rectangle((1, 5), 2, 1, linewidth=1, edgecolor='black', facecolor='white')
ax.add_patch(rect_attach)
ax.text(1.5, 5.5, 'Attach\nSuccess', ha='center', va='center')
rect_conn = Rectangle((4, 5), 2, 1, linewidth=1, edgecolor='black', facecolor='white')
ax.add_patch(rect_conn)
ax.text(4.5, 5.5, 'Connection\nSuccess', ha='center', va='center')
# 释放EPS承载完成
rect_done = Rectangle((7, 5), 2, 1, linewidth=1, edgecolor='black', facecolor='white')
ax.add_patch(rect_done)
ax.text(8, 5.5, 'Release\nDone', ha='center', va='center')
# UE端发起释放EPS承载 -> RRC连接释放
ax.annotate('', xy=(3, 9.5), xytext=(4, 9.5), arrowprops=dict(arrowstyle='->'))
# RRC连接释放 -> Detach请求
ax.annotate('', xy=(6, 9.5), xytext=(7, 9.5), arrowprops=dict(arrowstyle='->'))
# Detach请求 -> 信令Attach success/connection success等信令
ax.annotate('', xy=(1, 8), xytext=(1, 5.5), arrowprops=dict(arrowstyle='->'))
ax.annotate('', xy=(4, 8), xytext=(4, 5.5), arrowprops=dict(arrowstyle='->'))
# 信令Attach success/connection success等信令 -> 释放EPS承载完成
ax.annotate('', xy=(3, 5.5), xytext=(7, 5.5), arrowprops=dict(arrowstyle='->'))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
plt.show()
```