diff --git a/add_road_sign/main.py b/add_road_sign/main.py new file mode 100644 index 000000000000..e62ddd42020b --- /dev/null +++ b/add_road_sign/main.py @@ -0,0 +1,45 @@ +from matplotlib.path import Path +import matplotlib.pyplot as plt + + +def custom_box_style(x0, y0, width, height, mutation_size): + """ + Given the location and size of the box, return the path of the box around + it. Rotation is automatically taken care of. + + Parameters + ---------- + x0, y0, width, height : float + Box location and size. + mutation_size : float + Mutation reference scale, typically the text font size. + """ + # padding + mypad = 0.3 + pad = mutation_size * mypad + # width and height with padding added. + width = width + 2 * pad + height = height + 2 * pad + # boundary of the padded box + x0, y0 = x0 - pad, y0 - pad + x1, y1 = x0 + width, y0 + height + # return the new path + return Path([(x0, y0), (x1, y0), (x1, y1), (x0, y1), + (x0-pad, (y0+y1)/2), (x0, y0), (x0, y0)], + closed=True) + +#设置一号参数 +fig, ax = plt.subplots(figsize=(3, 3)) +ax.text(0.5, 0.5, "Test", size=30, va="center", ha="center", rotation=30, + bbox=dict(boxstyle=custom_box_style, alpha=0.2)) + +#设置二号参数 +fig, ax = plt.subplots(figsize=(5, 5)) +t = ax.text(0.5, 0.5, "Direction", + ha="center", va="center", rotation=45, size=15, + bbox=dict(boxstyle="rarrow,pad=0.3", + fc="lightblue", ec="steelblue", lw=2)) + +# 显示图像 +plt.show() + diff --git a/add_road_sign/scratch_2.py b/add_road_sign/scratch_2.py new file mode 100644 index 000000000000..23c01c85e68a --- /dev/null +++ b/add_road_sign/scratch_2.py @@ -0,0 +1,24 @@ +import matplotlib.pyplot as plt +import numpy as np +fig, ax = plt.subplots(figsize=(3, 3)) + +ann = ax.annotate("Test", + xy=(0.2, 0.2), xycoords='data', + xytext=(0.8, 0.8), textcoords='data', + size=20, va="center", ha="center", + bbox=dict(boxstyle="round4", fc="w"), + arrowprops=dict(arrowstyle="fancy", + connectionstyle="arc3,rad=0.2", + relpos=(0., 0.), + fc="w")) + +ann = ax.annotate("Test", + xy=(0.2, 0.2), xycoords='data', + xytext=(0.8, 0.8), textcoords='data', + size=20, va="center", ha="center", + bbox=dict(boxstyle="round4", fc="w"), + arrowprops=dict(arrowstyle="fancy", + connectionstyle="arc3,rad=-0.2", + relpos=(1., 0.), + fc="w")) +plt.show() \ No newline at end of file diff --git a/add_road_sign/solve.py b/add_road_sign/solve.py new file mode 100644 index 000000000000..4454888ac8f0 --- /dev/null +++ b/add_road_sign/solve.py @@ -0,0 +1,32 @@ +import matplotlib.pyplot as plt +from matplotlib.patches import Arrow + +# 创建一个图形对象和子图 +fig, ax = plt.subplots() + +# 设置字体大小和颜色 +font_size = 25 +font_color = 'yellow' + +# 设置背景颜色 +background_color = 'green' + +# 绘制箭头路标,设置填充颜色和边框颜色 +arrow = Arrow(0.2, 0.2, 0.6, 0.6, width=0.5, edgecolor='yellow', facecolor='red', linewidth=3) +ax.add_patch(arrow) + +# 添加注释文本,设置字体大小和颜色 +ax.text(0.5, 0.9, 'RIGHT', ha='center', va='center', fontsize=font_size, color=font_color) + +# 设置图像范围 +ax.set_xlim(0, 1) +ax.set_ylim(0, 1) + +# 设置整个图形对象的背景颜色 +fig.patch.set_facecolor(background_color) + +# 隐藏坐标轴 +ax.axis('off') + +# 显示图像 +plt.show()