Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
matplotlib.github.com/1.5.0/examples/misc/rc_traits.py at plausible · matplotlib/matplotlib.github.com · 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
View 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 }}
Uh oh!
There was an error while loading.
Please reload this page
.
matplotlib
/
matplotlib.github.com
Public
Notifications
You must be signed in to change notification settings
Fork
62
Star
29
Code
Issues
1
Pull requests
2
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
plausible
Breadcrumbs
matplotlib.github.com
/
1.5.0
/
examples
/
misc
/
rc_traits.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
212 lines (173 loc) · 5.39 KB
plausible
Breadcrumbs
matplotlib.github.com
/
1.5.0
/
examples
/
misc
/
rc_traits.py
Copy path
Top
File metadata and controls
Code
Blame
212 lines (173 loc) · 5.39 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Here is some example code showing how to define some representative
# rc properties and construct a matplotlib artist using traits.
# matplotlib does not ship with enthought.traits, so you will need to
# install it separately.
from
__future__
import
print_function
import
sys
import
os
import
re
import
traits
.
api
as
traits
from
matplotlib
.
cbook
import
is_string_like
from
matplotlib
.
artist
import
Artist
doprint
=
True
flexible_true_trait
=
traits
.
Trait
(
True
,
{
'true'
:
True
,
't'
:
True
,
'yes'
:
True
,
'y'
:
True
,
'on'
:
True
,
True
:
True
,
'false'
:
False
,
'f'
:
False
,
'no'
:
False
,
'n'
:
False
,
'off'
:
False
,
False
:
False
})
flexible_false_trait
=
traits
.
Trait
(
False
,
flexible_true_trait
)
colors
=
{
'c'
:
'#00bfbf'
,
'b'
:
'#0000ff'
,
'g'
:
'#008000'
,
'k'
:
'#000000'
,
'm'
:
'#bf00bf'
,
'r'
:
'#ff0000'
,
'w'
:
'#ffffff'
,
'y'
:
'#bfbf00'
,
'gold'
:
'#FFD700'
,
'peachpuff'
:
'#FFDAB9'
,
'navajowhite'
:
'#FFDEAD'
,
}
def
hex2color
(
s
):
"Convert hex string (like html uses, eg, #efefef) to a r,g,b tuple"
return
tuple
([
int
(
n
,
16
)
/
255.0
for
n
in
(
s
[
1
:
3
],
s
[
3
:
5
],
s
[
5
:
7
])])
class
RGBA
(
traits
.
HasTraits
):
# r,g,b,a in the range 0-1 with default color 0,0,0,1 (black)
r
=
traits
.
Range
(
0.
,
1.
,
0.
)
g
=
traits
.
Range
(
0.
,
1.
,
0.
)
b
=
traits
.
Range
(
0.
,
1.
,
0.
)
a
=
traits
.
Range
(
0.
,
1.
,
1.
)
def
__init__
(
self
,
r
=
0.
,
g
=
0.
,
b
=
0.
,
a
=
1.
):
self
.
r
=
r
self
.
g
=
g
self
.
b
=
b
self
.
a
=
a
def
__repr__
(
self
):
return
'r,g,b,a = (%1.2f, %1.2f, %1.2f, %1.2f)'
%
\
(
self
.
r
,
self
.
g
,
self
.
b
,
self
.
a
)
def
tuple_to_rgba
(
ob
,
name
,
val
):
tup
=
[
float
(
x
)
for
x
in
val
]
if
len
(
tup
)
==
3
:
r
,
g
,
b
=
tup
return
RGBA
(
r
,
g
,
b
)
elif
len
(
tup
)
==
4
:
r
,
g
,
b
,
a
=
tup
return
RGBA
(
r
,
g
,
b
,
a
)
else
:
raise
ValueError
tuple_to_rgba
.
info
=
'a RGB or RGBA tuple of floats'
def
hex_to_rgba
(
ob
,
name
,
val
):
rgx
=
re
.
compile
(
'^#[0-9A-Fa-f]{6}$'
)
if
not
is_string_like
(
val
):
raise
TypeError
if
rgx
.
match
(
val
)
is
None
:
raise
ValueError
r
,
g
,
b
=
hex2color
(
val
)
return
RGBA
(
r
,
g
,
b
,
1.0
)
hex_to_rgba
.
info
=
'a hex color string'
def
colorname_to_rgba
(
ob
,
name
,
val
):
hex
=
colors
[
val
.
lower
()]
r
,
g
,
b
=
hex2color
(
hex
)
return
RGBA
(
r
,
g
,
b
,
1.0
)
colorname_to_rgba
.
info
=
'a named color'
def
float_to_rgba
(
ob
,
name
,
val
):
val
=
float
(
val
)
return
RGBA
(
val
,
val
,
val
,
1.
)
float_to_rgba
.
info
=
'a grayscale intensity'
Color
=
traits
.
Trait
(
RGBA
(),
float_to_rgba
,
colorname_to_rgba
,
RGBA
,
hex_to_rgba
,
tuple_to_rgba
)
def
file_exists
(
ob
,
name
,
val
):
fh
=
file
(
val
,
'r'
)
return
val
linestyles
=
(
'-'
,
'--'
,
'-.'
,
':'
,
'steps'
,
'None'
)
TICKLEFT
,
TICKRIGHT
,
TICKUP
,
TICKDOWN
=
range
(
4
)
linemarkers
=
(
None
,
'.'
,
','
,
'o'
,
'^'
,
'v'
,
'<'
,
'>'
,
's'
,
'+'
,
'x'
,
'd'
,
'D'
,
'|'
,
'_'
,
'h'
,
'H'
,
'p'
,
'1'
,
'2'
,
'3'
,
'4'
,
TICKLEFT
,
TICKRIGHT
,
TICKUP
,
TICKDOWN
,
'None'
)
class
LineRC
(
traits
.
HasTraits
):
linewidth
=
traits
.
Float
(
0.5
)
linestyle
=
traits
.
Trait
(
*
linestyles
)
color
=
Color
marker
=
traits
.
Trait
(
*
linemarkers
)
markerfacecolor
=
Color
markeredgecolor
=
Color
markeredgewidth
=
traits
.
Float
(
0.5
)
markersize
=
traits
.
Float
(
6
)
antialiased
=
flexible_true_trait
data_clipping
=
flexible_false_trait
class
PatchRC
(
traits
.
HasTraits
):
linewidth
=
traits
.
Float
(
1.0
)
facecolor
=
Color
edgecolor
=
Color
antialiased
=
flexible_true_trait
timezones
=
'UTC'
,
'US/Central'
,
'ES/Eastern'
# fixme: and many more
backends
=
(
'GTKAgg'
,
'Cairo'
,
'GDK'
,
'GTK'
,
'Agg'
,
'GTKCairo'
,
'PS'
,
'SVG'
,
'Template'
,
'TkAgg'
,
'WX'
)
class
RC
(
traits
.
HasTraits
):
backend
=
traits
.
Trait
(
*
backends
)
interactive
=
flexible_false_trait
toolbar
=
traits
.
Trait
(
'toolbar2'
,
'classic'
,
None
)
timezone
=
traits
.
Trait
(
*
timezones
)
lines
=
traits
.
Trait
(
LineRC
())
patch
=
traits
.
Trait
(
PatchRC
())
rc
=
RC
()
rc
.
lines
.
color
=
'r'
if
doprint
:
print
(
'RC'
)
rc
.
print_traits
()
print
(
'RC lines'
)
rc
.
lines
.
print_traits
()
print
(
'RC patches'
)
rc
.
patch
.
print_traits
()
class
Patch
(
Artist
,
traits
.
HasTraits
):
linewidth
=
traits
.
Float
(
0.5
)
facecolor
=
Color
fc
=
facecolor
edgecolor
=
Color
fill
=
flexible_true_trait
def
__init__
(
self
,
edgecolor
=
None
,
facecolor
=
None
,
linewidth
=
None
,
antialiased
=
None
,
fill
=
1
,
**
kwargs
):
Artist
.
__init__
(
self
)
if
edgecolor
is
None
:
edgecolor
=
rc
.
patch
.
edgecolor
if
facecolor
is
None
:
facecolor
=
rc
.
patch
.
facecolor
if
linewidth
is
None
:
linewidth
=
rc
.
patch
.
linewidth
if
antialiased
is
None
:
antialiased
=
rc
.
patch
.
antialiased
self
.
edgecolor
=
edgecolor
self
.
facecolor
=
facecolor
self
.
linewidth
=
linewidth
self
.
antialiased
=
antialiased
self
.
fill
=
fill
p
=
Patch
()
p
.
facecolor
=
'#bfbf00'
p
.
edgecolor
=
'gold'
p
.
facecolor
=
(
1
,
.5
,
.5
,
.25
)
p
.
facecolor
=
0.25
p
.
fill
=
'f'
print
(
'p.facecolor'
,
type
(
p
.
facecolor
),
p
.
facecolor
)
print
(
'p.fill'
,
type
(
p
.
fill
),
p
.
fill
)
if
p
.
fill_
:
print
(
'fill'
)
else
:
print
(
'no fill'
)
if
doprint
:
print
()
print
(
'Patch'
)
p
.
print_traits
()
You can’t perform that action at this time.