-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Fix 3D axes to properly support non-linear scales (log, symlog, etc.) #30980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d9afaf6
Fix 3D axes to properly support non-linear scales (log, symlog, etc.)
scottshambaugh 1afb165
Cleanup and linting
scottshambaugh 0fb87fc
Have zoom and pan work with 3D log scales
scottshambaugh 657942a
Fix test regressions
scottshambaugh 5112998
Respect limit_range_for_scale in 3d
scottshambaugh 9821771
Break repeated code out to a helper function
scottshambaugh 9b057ea
Commonize axis scale setting code
scottshambaugh 280acb8
Commonize autoscaling each axis
scottshambaugh 2e19d87
Cleanup and consolidation
scottshambaugh 6b3de8f
Code for 3d scale transform tests
scottshambaugh 02d4fdf
Docstring cleanup and coordinates explainer
scottshambaugh f4ce6ba
Loosen tolerance on flaky image comparison tests
scottshambaugh d46c5df
Fix 3d hover coordinates with scaled axes
scottshambaugh 24ab58b
Add gallery example and whats new for 3d scales
scottshambaugh a24160f
Factor repeated code into proj3d functions
scottshambaugh 8b8c7aa
Code review cleanup
scottshambaugh 5d335a3
More 3D log scale tests
scottshambaugh 77038d3
Fix empty plot scale handling
scottshambaugh ac6722e
Combine tests for 3d artists with log scales
scottshambaugh 418a488
Baseline images for scale3d tests
scottshambaugh 3050aae
Code review updates
scottshambaugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| Non-linear scales on 3D axes | ||
| ---------------------------- | ||
|
|
||
| Resolving a long-standing issue, 3D axes now support non-linear axis scales | ||
| such as 'log', 'symlog', 'logit', 'asinh', and custom 'function' scales, just | ||
| like 2D axes. Use `~.Axes3D.set_xscale`, `~.Axes3D.set_yscale`, and | ||
| `~.Axes3D.set_zscale` to set the scale for each axis independently. | ||
|
|
||
| .. plot:: | ||
| :include-source: true | ||
| :alt: A 3D plot with a linear x-axis, logarithmic y-axis, and symlog z-axis. | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
|
|
||
| # A sine chirp with increasing frequency and amplitude | ||
| x = np.linspace(0, 1, 400) # time | ||
| y = 10 ** (2 * x) # frequency, growing exponentially from 1 to 100 Hz | ||
| phase = 2 * np.pi * (10 ** (2 * x) - 1) / (2 * np.log(10)) | ||
| z = np.sin(phase) * x ** 2 * 10 # amplitude, growing quadratically | ||
|
|
||
| fig = plt.figure() | ||
| ax = fig.add_subplot(projection='3d') | ||
| ax.plot(x, y, z) | ||
|
|
||
| ax.set_xlabel('Time (linear)') | ||
| ax.set_ylabel('Frequency, Hz (log)') | ||
| ax.set_zlabel('Amplitude (symlog)') | ||
|
|
||
| ax.set_yscale('log') | ||
| ax.set_zscale('symlog') | ||
|
|
||
| plt.show() | ||
|
|
||
| See `matplotlib.scale` for details on all available scales and their parameters. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """ | ||
| ================================ | ||
| Scales on 3D (Log, Symlog, etc.) | ||
| ================================ | ||
|
|
||
| Demonstrate how to use non-linear scales such as logarithmic scales on 3D axes. | ||
|
|
||
| 3D axes support the same axis scales as 2D plots: 'linear', 'log', 'symlog', | ||
| 'logit', 'asinh', and custom 'function' scales. This example shows a mix of | ||
| scales: linear on X, log on Y, and symlog on Z. | ||
|
|
||
| For a complete list of built-in scales, see `matplotlib.scale`. For an overview | ||
| of scale transformations, see :doc:`/gallery/scales/scales`. | ||
| """ | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
|
|
||
| # A sine chirp with increasing frequency and amplitude | ||
| x = np.linspace(0, 1, 400) # time | ||
| y = 10 ** (2 * x) # frequency, growing exponentially from 1 to 100 Hz | ||
| phase = 2 * np.pi * (10 ** (2 * x) - 1) / (2 * np.log(10)) | ||
| z = np.sin(phase) * x **2 * 10 # amplitude, growing quadratically | ||
|
|
||
| fig = plt.figure() | ||
| ax = fig.add_subplot(projection='3d') | ||
| ax.plot(x, y, z) | ||
|
|
||
| ax.set_xlabel('Time (linear)') | ||
| ax.set_ylabel('Frequency, Hz (log)') | ||
| ax.set_zlabel('Amplitude (symlog)') | ||
|
|
||
| ax.set_yscale('log') | ||
| ax.set_zscale('symlog') | ||
|
|
||
| plt.show() | ||
|
|
||
| # %% | ||
| # | ||
| # .. admonition:: References | ||
| # | ||
| # The use of the following functions, methods, classes and modules is shown | ||
| # in this example: | ||
| # | ||
| # - `mpl_toolkits.mplot3d.axes3d.Axes3D.set_xscale` | ||
| # - `mpl_toolkits.mplot3d.axes3d.Axes3D.set_yscale` | ||
| # - `mpl_toolkits.mplot3d.axes3d.Axes3D.set_zscale` | ||
| # - `matplotlib.scale` | ||
| # | ||
| # .. tags:: | ||
| # plot-type: 3D, | ||
| # level: beginner |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.