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_skew.py at v3.10.5 · 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.5
Breadcrumbs
matplotlib
/
lib
/
matplotlib
/
tests
/
test_skew.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
170 lines (135 loc) · 6.2 KB
v3.10.5
Breadcrumbs
matplotlib
/
lib
/
matplotlib
/
tests
/
test_skew.py
Copy path
Top
File metadata and controls
Code
Blame
170 lines (135 loc) · 6.2 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
"""
Testing that skewed Axes properly work.
"""
from
contextlib
import
ExitStack
import
itertools
import
platform
import
matplotlib
.
pyplot
as
plt
from
matplotlib
.
testing
.
decorators
import
image_comparison
from
matplotlib
.
axes
import
Axes
import
matplotlib
.
transforms
as
transforms
import
matplotlib
.
axis
as
maxis
import
matplotlib
.
spines
as
mspines
import
matplotlib
.
patches
as
mpatch
from
matplotlib
.
projections
import
register_projection
# The sole purpose of this class is to look at the upper, lower, or total
# interval as appropriate and see what parts of the tick to draw, if any.
class
SkewXTick
(
maxis
.
XTick
):
def
draw
(
self
,
renderer
):
with
ExitStack
()
as
stack
:
for
artist
in
[
self
.
gridline
,
self
.
tick1line
,
self
.
tick2line
,
self
.
label1
,
self
.
label2
]:
stack
.
callback
(
artist
.
set_visible
,
artist
.
get_visible
())
needs_lower
=
transforms
.
interval_contains
(
self
.
axes
.
lower_xlim
,
self
.
get_loc
())
needs_upper
=
transforms
.
interval_contains
(
self
.
axes
.
upper_xlim
,
self
.
get_loc
())
self
.
tick1line
.
set_visible
(
self
.
tick1line
.
get_visible
()
and
needs_lower
)
self
.
label1
.
set_visible
(
self
.
label1
.
get_visible
()
and
needs_lower
)
self
.
tick2line
.
set_visible
(
self
.
tick2line
.
get_visible
()
and
needs_upper
)
self
.
label2
.
set_visible
(
self
.
label2
.
get_visible
()
and
needs_upper
)
super
().
draw
(
renderer
)
def
get_view_interval
(
self
):
return
self
.
axes
.
xaxis
.
get_view_interval
()
# This class exists to provide two separate sets of intervals to the tick,
# as well as create instances of the custom tick
class
SkewXAxis
(
maxis
.
XAxis
):
def
_get_tick
(
self
,
major
):
return
SkewXTick
(
self
.
axes
,
None
,
major
=
major
)
def
get_view_interval
(
self
):
return
self
.
axes
.
upper_xlim
[
0
],
self
.
axes
.
lower_xlim
[
1
]
# This class exists to calculate the separate data range of the
# upper X-axis and draw the spine there. It also provides this range
# to the X-axis artist for ticking and gridlines
class
SkewSpine
(
mspines
.
Spine
):
def
_adjust_location
(
self
):
pts
=
self
.
_path
.
vertices
if
self
.
spine_type
==
'top'
:
pts
[:,
0
]
=
self
.
axes
.
upper_xlim
else
:
pts
[:,
0
]
=
self
.
axes
.
lower_xlim
# This class handles registration of the skew-xaxes as a projection as well
# as setting up the appropriate transformations. It also overrides standard
# spines and axes instances as appropriate.
class
SkewXAxes
(
Axes
):
# The projection must specify a name. This will be used be the
# user to select the projection, i.e. ``subplot(projection='skewx')``.
name
=
'skewx'
def
_init_axis
(
self
):
# Taken from Axes and modified to use our modified X-axis
self
.
xaxis
=
SkewXAxis
(
self
)
self
.
spines
.
top
.
register_axis
(
self
.
xaxis
)
self
.
spines
.
bottom
.
register_axis
(
self
.
xaxis
)
self
.
yaxis
=
maxis
.
YAxis
(
self
)
self
.
spines
.
left
.
register_axis
(
self
.
yaxis
)
self
.
spines
.
right
.
register_axis
(
self
.
yaxis
)
def
_gen_axes_spines
(
self
):
spines
=
{
'top'
:
SkewSpine
.
linear_spine
(
self
,
'top'
),
'bottom'
:
mspines
.
Spine
.
linear_spine
(
self
,
'bottom'
),
'left'
:
mspines
.
Spine
.
linear_spine
(
self
,
'left'
),
'right'
:
mspines
.
Spine
.
linear_spine
(
self
,
'right'
)}
return
spines
def
_set_lim_and_transforms
(
self
):
"""
This is called once when the plot is created to set up all the
transforms for the data, text and grids.
"""
rot
=
30
# Get the standard transform setup from the Axes base class
super
().
_set_lim_and_transforms
()
# Need to put the skew in the middle, after the scale and limits,
# but before the transAxes. This way, the skew is done in Axes
# coordinates thus performing the transform around the proper origin
# We keep the pre-transAxes transform around for other users, like the
# spines for finding bounds
self
.
transDataToAxes
=
(
self
.
transScale
+
(
self
.
transLimits
+
transforms
.
Affine2D
().
skew_deg
(
rot
,
0
)))
# Create the full transform from Data to Pixels
self
.
transData
=
self
.
transDataToAxes
+
self
.
transAxes
# Blended transforms like this need to have the skewing applied using
# both axes, in axes coords like before.
self
.
_xaxis_transform
=
(
transforms
.
blended_transform_factory
(
self
.
transScale
+
self
.
transLimits
,
transforms
.
IdentityTransform
())
+
transforms
.
Affine2D
().
skew_deg
(
rot
,
0
))
+
self
.
transAxes
@
property
def
lower_xlim
(
self
):
return
self
.
axes
.
viewLim
.
intervalx
@
property
def
upper_xlim
(
self
):
pts
=
[[
0.
,
1.
], [
1.
,
1.
]]
return
self
.
transDataToAxes
.
inverted
().
transform
(
pts
)[:,
0
]
# Now register the projection with matplotlib so the user can select
# it.
register_projection
(
SkewXAxes
)
@
image_comparison
([
'skew_axes.png'
],
remove_text
=
True
)
def
test_set_line_coll_dash_image
():
fig
=
plt
.
figure
()
ax
=
fig
.
add_subplot
(
1
,
1
,
1
,
projection
=
'skewx'
)
ax
.
set_xlim
(
-
50
,
50
)
ax
.
set_ylim
(
50
,
-
50
)
ax
.
grid
(
True
)
# An example of a slanted line at constant X
ax
.
axvline
(
0
,
color
=
'b'
)
@
image_comparison
([
'skew_rects.png'
],
remove_text
=
True
,
tol
=
0
if
platform
.
machine
()
==
'x86_64'
else
0.009
)
def
test_skew_rectangle
():
fix
,
axes
=
plt
.
subplots
(
5
,
5
,
sharex
=
True
,
sharey
=
True
,
figsize
=
(
8
,
8
))
axes
=
axes
.
flat
rotations
=
list
(
itertools
.
product
([
-
3
,
-
1
,
0
,
1
,
3
],
repeat
=
2
))
axes
[
0
].
set_xlim
([
-
3
,
3
])
axes
[
0
].
set_ylim
([
-
3
,
3
])
axes
[
0
].
set_aspect
(
'equal'
,
share
=
True
)
for
ax
, (
xrots
,
yrots
)
in
zip
(
axes
,
rotations
):
xdeg
,
ydeg
=
45
*
xrots
,
45
*
yrots
t
=
transforms
.
Affine2D
().
skew_deg
(
xdeg
,
ydeg
)
ax
.
set_title
(
f'Skew of
{
xdeg
}
in X and
{
ydeg
}
in Y'
)
ax
.
add_patch
(
mpatch
.
Rectangle
([
-
1
,
-
1
],
2
,
2
,
transform
=
t
+
ax
.
transData
,
alpha
=
0.5
,
facecolor
=
'coral'
))
plt
.
subplots_adjust
(
wspace
=
0
,
left
=
0.01
,
right
=
0.99
,
bottom
=
0.01
,
top
=
0.99
)
You can’t perform that action at this time.