Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add road sign #26360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions add_road_sign/main.py
Original file line number Diff line number Diff line change
@@ -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()

24 changes: 24 additions & 0 deletions add_road_sign/scratch_2.py
Original file line number Diff line number Diff line change
@@ -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()
32 changes: 32 additions & 0 deletions add_road_sign/solve.py
Original file line number Diff line number Diff line change
@@ -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()