FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/style_sheets/plot_ggplot.py at master · feisuo/matplotlib · GitHub
feisuo
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
style_sheets
/
plot_ggplot.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (40 loc) · 1.38 KB
Breadcrumbs
matplotlib
/
examples
/
style_sheets
/
plot_ggplot.py
Copy path
File metadata and controls
51 lines (40 loc) · 1.38 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
"""
This example demonstrates the "ggplot" style, which adjusts the style to
emulate ggplot_ (a popular plotting package for R_).
These settings were shamelessly stolen from [1]_ (with permission).
.. [1] http://www.huyng.com/posts/sane-color-scheme-for-matplotlib/
.. _ggplot: http://had.co.nz/ggplot/
.. _R: http://www.r-project.org/
"""
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
plt
.
style
.
use
(
'ggplot'
)
fig
,
axes
=
plt
.
subplots
(
ncols
=
2
,
nrows
=
2
)
ax1
,
ax2
,
ax3
,
ax4
=
axes
.
ravel
()
# scatter plot (Note: `plt.scatter` doesn't use default colors)
x
,
y
=
np
.
random
.
normal
(
size
=
(
2
,
200
))
ax1
.
plot
(
x
,
y
,
'o'
)
# sinusoidal lines with colors from default color cycle
L
=
2
*
np
.
pi
x
=
np
.
linspace
(
0
,
L
)
ncolors
=
len
(
plt
.
rcParams
[
'axes.prop_cycle'
])
shift
=
np
.
linspace
(
0
,
L
,
ncolors
,
endpoint
=
False
)
for
s
in
shift
:
ax2
.
plot
(
x
,
np
.
sin
(
x
+
s
),
'-'
)
ax2
.
margins
(
0
)
# bar graphs
x
=
np
.
arange
(
5
)
y1
,
y2
=
np
.
random
.
randint
(
1
,
25
,
size
=
(
2
,
5
))
width
=
0.25
ax3
.
bar
(
x
,
y1
,
width
)
ax3
.
bar
(
x
+
width
,
y2
,
width
,
color
=
list
(
plt
.
rcParams
[
'axes.prop_cycle'
])[
2
][
'color'
])
ax3
.
set_xticks
(
x
+
width
)
ax3
.
set_xticklabels
([
'a'
,
'b'
,
'c'
,
'd'
,
'e'
])
# circles with colors from default color cycle
for
i
,
color
in
enumerate
(
plt
.
rcParams
[
'axes.prop_cycle'
]):
xy
=
np
.
random
.
normal
(
size
=
2
)
ax4
.
add_patch
(
plt
.
Circle
(
xy
,
radius
=
0.3
,
color
=
color
[
'color'
]))
ax4
.
axis
(
'equal'
)
ax4
.
margins
(
0
)
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL