Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24ab58b

Browse files
Add gallery example and whats new for 3d scales
1 parent d46c5df commit 24ab58b

3 files changed

Lines changed: 90 additions & 2 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Non-linear scales on 3D axes
2+
----------------------------
3+
4+
Resolving a long-standing issue, 3D axes now support non-linear axis scales
5+
such as 'log', 'symlog', 'logit', 'asinh', and custom 'function' scales, just
6+
like 2D axes. Use `~.Axes3D.set_xscale`, `~.Axes3D.set_yscale`, and
7+
`~.Axes3D.set_zscale` to set the scale for each axis independently.
8+
9+
.. plot::
10+
:include-source: true
11+
:alt: A 3D plot with a linear x-axis, logarithmic y-axis, and symlog z-axis.
12+
13+
import matplotlib.pyplot as plt
14+
import numpy as np
15+
16+
# A sine chirp with increasing frequency and amplitude
17+
x = np.linspace(0, 1, 400) # time
18+
y = 10 ** (2 * x) # frequency, growing exponentially from 1 to 100 Hz
19+
phase = 2 * np.pi * (10 ** (2 * x) - 1) / (2 * np.log(10))
20+
z = np.sin(phase) * x ** 2 * 10 # amplitude, growing quadratically
21+
22+
fig = plt.figure()
23+
ax = fig.add_subplot(projection='3d')
24+
ax.plot(x, y, z)
25+
26+
ax.set_xlabel('Time (linear)')
27+
ax.set_ylabel('Frequency, Hz (log)')
28+
ax.set_zlabel('Amplitude (symlog)')
29+
30+
ax.set_yscale('log')
31+
ax.set_zscale('symlog')
32+
33+
plt.show()
34+
35+
See `matplotlib.scale` for details on all available scales and their parameters.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
================================
3+
Scales on 3D (Log, Symlog, etc.)
4+
================================
5+
6+
Demonstrate how to use non-linear scales such as logarithmic scales on 3D axes.
7+
8+
3D axes support the same axis scales as 2D plots: 'linear', 'log', 'symlog',
9+
'logit', 'asinh', and custom 'function' scales. This example shows a mix of
10+
scales: linear on X, log on Y, and symlog on Z.
11+
12+
For a complete list of built-in scales, see `matplotlib.scale`. For an overview
13+
of scale transformations, see :doc:`/gallery/scales/scales`.
14+
"""
15+
16+
import matplotlib.pyplot as plt
17+
import numpy as np
18+
19+
# A sine chirp with increasing frequency and amplitude
20+
x = np.linspace(0, 1, 400) # time
21+
y = 10 ** (2 * x) # frequency, growing exponentially from 1 to 100 Hz
22+
phase = 2 * np.pi * (10 ** (2 * x) - 1) / (2 * np.log(10))
23+
z = np.sin(phase) * x **2 * 10 # amplitude, growing quadratically
24+
25+
fig = plt.figure()
26+
ax = fig.add_subplot(projection='3d')
27+
ax.plot(x, y, z)
28+
29+
ax.set_xlabel('Time (linear)')
30+
ax.set_ylabel('Frequency, Hz (log)')
31+
ax.set_zlabel('Amplitude (symlog)')
32+
33+
ax.set_yscale('log')
34+
ax.set_zscale('symlog')
35+
36+
plt.show()
37+
38+
# %%
39+
#
40+
# .. admonition:: References
41+
#
42+
# The use of the following functions, methods, classes and modules is shown
43+
# in this example:
44+
#
45+
# - `mpl_toolkits.mplot3d.axes3d.Axes3D.set_xscale`
46+
# - `mpl_toolkits.mplot3d.axes3d.Axes3D.set_yscale`
47+
# - `mpl_toolkits.mplot3d.axes3d.Axes3D.set_zscale`
48+
# - `matplotlib.scale`
49+
#
50+
# .. tags::
51+
# plot-type: 3D,
52+
# level: beginner

galleries/examples/scales/scales.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
66
Illustrate the scale transformations applied to axes, e.g. log, symlog, logit.
77
8-
See `matplotlib.scale` for a full list of built-in scales, and
9-
:doc:`/gallery/scales/custom_scale` for how to create your own scale.
8+
See `matplotlib.scale` for a full list of built-in scales,
9+
:doc:`/gallery/scales/custom_scale` for how to create your own scale, and
10+
:doc:`/gallery/mplot3d/scales3d` for using scales on 3D axes.
1011
"""
1112

1213
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)