FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/mplot3d/2dcollections3d.py at master · mitar/matplotlib · GitHub
mitar
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
mplot3d
/
2dcollections3d.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (40 loc) · 1.26 KB
Breadcrumbs
matplotlib
/
examples
/
mplot3d
/
2dcollections3d.py
Copy path
File metadata and controls
50 lines (40 loc) · 1.26 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
"""
=======================
Plot 2D data on 3D plot
=======================
Demonstrates using ax.plot's zdir keyword to plot 2D data on
selective axes of a 3D plot.
"""
from
mpl_toolkits
.
mplot3d
import
Axes3D
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
fig
=
plt
.
figure
()
ax
=
fig
.
gca
(
projection
=
'3d'
)
# Plot a sin curve using the x and y axes.
x
=
np
.
linspace
(
0
,
1
,
100
)
y
=
np
.
sin
(
x
*
2
*
np
.
pi
)
/
2
+
0.5
ax
.
plot
(
x
,
y
,
zs
=
0
,
zdir
=
'z'
,
label
=
'curve in (x,y)'
)
# Plot scatterplot data (20 2D points per colour) on the x and z axes.
colors
=
(
'r'
,
'g'
,
'b'
,
'k'
)
# Fixing random state for reproducibility
np
.
random
.
seed
(
19680801
)
x
=
np
.
random
.
sample
(
20
*
len
(
colors
))
y
=
np
.
random
.
sample
(
20
*
len
(
colors
))
c_list
=
[]
for
c
in
colors
:
c_list
.
extend
([
c
]
*
20
)
# By using zdir='y', the y value of these points is fixed to the zs value 0
# and the (x,y) points are plotted on the x and z axes.
ax
.
scatter
(
x
,
y
,
zs
=
0
,
zdir
=
'y'
,
c
=
c_list
,
label
=
'points in (x,z)'
)
# Make legend, set axes limits and labels
ax
.
legend
()
ax
.
set_xlim
(
0
,
1
)
ax
.
set_ylim
(
0
,
1
)
ax
.
set_zlim
(
0
,
1
)
ax
.
set_xlabel
(
'X'
)
ax
.
set_ylabel
(
'Y'
)
ax
.
set_zlabel
(
'Z'
)
# Customize the view angle so it's easier to see that the scatter points lie
# on the plane y=0
ax
.
view_init
(
elev
=
20.
,
azim
=
-
35
)
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL