Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
matplotlib/lib/matplotlib/tests/test_arrow_patches.py at v3.10.9 · matplotlib/matplotlib · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
matplotlib
matplotlib
Repository navigation
Code
Issues
1.1k
(1.1k)
Pull requests
430
(430)
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
v3.10.9
Breadcrumbs
matplotlib
/
lib
/
matplotlib
/
tests
/
test_arrow_patches.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
179 lines (141 loc) · 6.42 KB
v3.10.9
Breadcrumbs
matplotlib
/
lib
/
matplotlib
/
tests
/
test_arrow_patches.py
Copy path
Top
File metadata and controls
Code
Blame
179 lines (141 loc) · 6.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import
pytest
import
platform
import
matplotlib
.
pyplot
as
plt
from
matplotlib
.
testing
.
decorators
import
image_comparison
import
matplotlib
.
patches
as
mpatches
def
draw_arrow
(
ax
,
t
,
r
):
ax
.
annotate
(
''
,
xy
=
(
0.5
,
0.5
+
r
),
xytext
=
(
0.5
,
0.5
),
size
=
30
,
arrowprops
=
dict
(
arrowstyle
=
t
,
fc
=
"b"
,
ec
=
'k'
))
@
image_comparison
([
'fancyarrow_test_image.png'
],
tol
=
0
if
platform
.
machine
()
==
'x86_64'
else
0.012
)
def
test_fancyarrow
():
# Added 0 to test division by zero error described in issue 3930
r
=
[
0.4
,
0.3
,
0.2
,
0.1
,
0
]
t
=
[
"fancy"
,
"simple"
,
mpatches
.
ArrowStyle
.
Fancy
()]
fig
,
axs
=
plt
.
subplots
(
len
(
t
),
len
(
r
),
squeeze
=
False
,
figsize
=
(
8
,
4.5
),
subplot_kw
=
dict
(
aspect
=
1
))
for
i_r
,
r1
in
enumerate
(
r
):
for
i_t
,
t1
in
enumerate
(
t
):
ax
=
axs
[
i_t
,
i_r
]
draw_arrow
(
ax
,
t1
,
r1
)
ax
.
tick_params
(
labelleft
=
False
,
labelbottom
=
False
)
@
image_comparison
([
'boxarrow_test_image.png'
])
def
test_boxarrow
():
styles
=
mpatches
.
BoxStyle
.
get_styles
()
n
=
len
(
styles
)
spacing
=
1.2
figheight
=
(
n
*
spacing
+
.5
)
fig
=
plt
.
figure
(
figsize
=
(
4
/
1.5
,
figheight
/
1.5
))
fontsize
=
0.3
*
72
for
i
,
stylename
in
enumerate
(
sorted
(
styles
)):
fig
.
text
(
0.5
, ((
n
-
i
)
*
spacing
-
0.5
)
/
figheight
,
stylename
,
ha
=
"center"
,
size
=
fontsize
,
transform
=
fig
.
transFigure
,
bbox
=
dict
(
boxstyle
=
stylename
,
fc
=
"w"
,
ec
=
"k"
))
def
__prepare_fancyarrow_dpi_cor_test
():
"""
Convenience function that prepares and returns a FancyArrowPatch. It aims
at being used to test that the size of the arrow head does not depend on
the DPI value of the exported picture.
NB: this function *is not* a test in itself!
"""
fig2
=
plt
.
figure
(
"fancyarrow_dpi_cor_test"
,
figsize
=
(
4
,
3
),
dpi
=
50
)
ax
=
fig2
.
add_subplot
()
ax
.
set_xlim
([
0
,
1
])
ax
.
set_ylim
([
0
,
1
])
ax
.
add_patch
(
mpatches
.
FancyArrowPatch
(
posA
=
(
0.3
,
0.4
),
posB
=
(
0.8
,
0.6
),
lw
=
3
,
arrowstyle
=
'->'
,
mutation_scale
=
100
))
return
fig2
@
image_comparison
([
'fancyarrow_dpi_cor_100dpi.png'
],
remove_text
=
True
,
tol
=
0
if
platform
.
machine
()
==
'x86_64'
else
0.02
,
savefig_kwarg
=
dict
(
dpi
=
100
))
def
test_fancyarrow_dpi_cor_100dpi
():
"""
Check the export of a FancyArrowPatch @ 100 DPI. FancyArrowPatch is
instantiated through a dedicated function because another similar test
checks a similar export but with a different DPI value.
Remark: test only a rasterized format.
"""
__prepare_fancyarrow_dpi_cor_test
()
@
image_comparison
([
'fancyarrow_dpi_cor_200dpi.png'
],
remove_text
=
True
,
tol
=
0
if
platform
.
machine
()
==
'x86_64'
else
0.02
,
savefig_kwarg
=
dict
(
dpi
=
200
))
def
test_fancyarrow_dpi_cor_200dpi
():
"""
As test_fancyarrow_dpi_cor_100dpi, but exports @ 200 DPI. The relative size
of the arrow head should be the same.
"""
__prepare_fancyarrow_dpi_cor_test
()
@
image_comparison
([
'fancyarrow_dash.png'
],
remove_text
=
True
,
style
=
'default'
)
def
test_fancyarrow_dash
():
fig
,
ax
=
plt
.
subplots
()
e
=
mpatches
.
FancyArrowPatch
((
0
,
0
), (
0.5
,
0.5
),
arrowstyle
=
'-|>'
,
connectionstyle
=
'angle3,angleA=0,angleB=90'
,
mutation_scale
=
10.0
,
linewidth
=
2
,
linestyle
=
'dashed'
,
color
=
'k'
)
e2
=
mpatches
.
FancyArrowPatch
((
0
,
0
), (
0.5
,
0.5
),
arrowstyle
=
'-|>'
,
connectionstyle
=
'angle3'
,
mutation_scale
=
10.0
,
linewidth
=
2
,
linestyle
=
'dotted'
,
color
=
'k'
)
ax
.
add_patch
(
e
)
ax
.
add_patch
(
e2
)
@
image_comparison
([
'arrow_styles.png'
],
style
=
'mpl20'
,
remove_text
=
True
,
tol
=
0
if
platform
.
machine
()
==
'x86_64'
else
0.02
)
def
test_arrow_styles
():
styles
=
mpatches
.
ArrowStyle
.
get_styles
()
n
=
len
(
styles
)
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
8
,
8
))
ax
.
set_xlim
(
0
,
1
)
ax
.
set_ylim
(
-
1
,
n
)
fig
.
subplots_adjust
(
left
=
0
,
right
=
1
,
bottom
=
0
,
top
=
1
)
for
i
,
stylename
in
enumerate
(
sorted
(
styles
)):
patch
=
mpatches
.
FancyArrowPatch
((
0.1
+
(
i
%
2
)
*
0.05
,
i
),
(
0.45
+
(
i
%
2
)
*
0.05
,
i
),
arrowstyle
=
stylename
,
mutation_scale
=
25
)
ax
.
add_patch
(
patch
)
for
i
,
stylename
in
enumerate
([
']-['
,
']-'
,
'-['
,
'|-|'
]):
style
=
stylename
if
stylename
[
0
]
!=
'-'
:
style
+=
',angleA=ANGLE'
if
stylename
[
-
1
]
!=
'-'
:
style
+=
',angleB=ANGLE'
for
j
,
angle
in
enumerate
([
-
30
,
60
]):
arrowstyle
=
style
.
replace
(
'ANGLE'
,
str
(
angle
))
patch
=
mpatches
.
FancyArrowPatch
((
0.55
,
2
*
i
+
j
), (
0.9
,
2
*
i
+
j
),
arrowstyle
=
arrowstyle
,
mutation_scale
=
25
)
ax
.
add_patch
(
patch
)
@
image_comparison
([
'connection_styles.png'
],
style
=
'mpl20'
,
remove_text
=
True
,
tol
=
0
if
platform
.
machine
()
==
'x86_64'
else
0.013
)
def
test_connection_styles
():
styles
=
mpatches
.
ConnectionStyle
.
get_styles
()
n
=
len
(
styles
)
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
6
,
10
))
ax
.
set_xlim
(
0
,
1
)
ax
.
set_ylim
(
-
1
,
n
)
for
i
,
stylename
in
enumerate
(
sorted
(
styles
)):
patch
=
mpatches
.
FancyArrowPatch
((
0.1
,
i
), (
0.8
,
i
+
0.5
),
arrowstyle
=
"->"
,
connectionstyle
=
stylename
,
mutation_scale
=
25
)
ax
.
add_patch
(
patch
)
def
test_invalid_intersection
():
conn_style_1
=
mpatches
.
ConnectionStyle
.
Angle3
(
angleA
=
20
,
angleB
=
200
)
p1
=
mpatches
.
FancyArrowPatch
((
.2
,
.2
), (
.5
,
.5
),
connectionstyle
=
conn_style_1
)
with
pytest
.
raises
(
ValueError
):
plt
.
gca
().
add_patch
(
p1
)
conn_style_2
=
mpatches
.
ConnectionStyle
.
Angle3
(
angleA
=
20
,
angleB
=
199.9
)
p2
=
mpatches
.
FancyArrowPatch
((
.2
,
.2
), (
.5
,
.5
),
connectionstyle
=
conn_style_2
)
plt
.
gca
().
add_patch
(
p2
)
You can’t perform that action at this time.