Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
merge up v3.10.1#29700
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
merge up v3.10.1#29700
Changes from1 commit
436c94363d0149b07eae15c590cbee06c2735f47f790ca9310545b01c6afd1b2581353dd1e176f9e3c740db1cce872163219e4d4d05ebb732bfd3ee1a8e66461310545357f0de5b3694a6398614d4c63980309ee873b2fa9c1013ffe4fb2ec7237112dc6f6bd9b1797fe02b3b7bde695b365e09fb59ff19b99010c8d6b41592650ebed82818d6ec23ff2d3fe9b12c0f572d52242901324f89d4be6bc47f9be4e89ca8f098a6dc6a8874af205d2d6947d7fef8e6a9e25de3cbd2c0a9260ec3c21f8f9421330dc97390ae77611df01106c73f973f0b40a645e72df5c4a022cd63bdc00266bfd73a1ab1e0a53024b60edf8076b17774ca04d114f83e8b175b7bdf74830c0c56f44dca6b6f4a71b434f15ad26c401149e715e01134ef5a1401d734f5ceb70c24a2197aa6d535eb7b4466a46871dd07b5affd07c27dd9adf643ef5f311c2da34273b9978ab5b3d1774317568e1dbacefa0c36feb5eb5b6314d309f74bf3f82e4081af4b2ea20f40ed42384d94692c5c3dc3a23e3799d1835485d88d5d284598f455bd05640012033845aef46a33f673a28c9af95fefaf1366cb9e62ad13af51ba21811cf4763a71d915474b3994074676ef41a7ec3bdb728f4f3d478b4f94a42944994d3cf53d9fe0dadd23b173526785e2495bbc33361fb6fc816914d07d6d94f80dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,83 @@ | ||
| """ | ||
| ========= | ||
| Logscale | ||
| ========= | ||
| Examples of plots with logarithmic axes. | ||
| You can set the x/y axes to be logarithmic by passing "log" to `~.Axes.set_xscale` / | ||
| `~.Axes.set_yscale`. | ||
| Convenience functions ``semilogx``, ``semilogy``, and ``loglog`` | ||
| ---------------------------------------------------------------- | ||
| Since plotting data on semi-logarithmic or double-logarithmic scales is very common, | ||
| the functions `~.Axes.semilogx`, `~.Axes.semilogy`, and `~.Axes.loglog` are shortcuts | ||
| for setting the scale and plotting data; e.g. ``ax.semilogx(x, y)`` is equivalent to | ||
| ``ax.set_xscale('log'); ax.plot(x, y)``. | ||
| """ | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| fig, (ax1, ax2, ax3) = plt.subplots(1, 3, layout='constrained', figsize=(7, 7/3)) | ||
| # log x axis | ||
| t = np.arange(0.01, 10.0, 0.01) | ||
| ax1.semilogx(t, np.sin(2 * np.pi * t)) | ||
| ax1.set(title='semilogx') | ||
| ax1.grid() | ||
| ax1.grid(which="minor", color="0.9") | ||
| # log y axis | ||
| x = np.arange(4) | ||
| ax2.semilogy(4*x, 10**x, 'o--') | ||
| ax2.set(title='semilogy') | ||
| ax2.grid() | ||
| ax2.grid(which="minor", color="0.9") | ||
| # log x and y axis | ||
| x =np.array([1, 10, 100, 1000]) | ||
| ax3.loglog(x, 5 * x, 'o--') | ||
| ax3.set(title='loglog') | ||
| ax3.grid() | ||
| ax3.grid(which="minor", color="0.9") | ||
| # %% | ||
| # Logarithms with other bases | ||
| # --------------------------- | ||
| # By default, the log scale is to the base 10. One can change this via the *base* | ||
| # parameter. | ||
| fig, ax = plt.subplots() | ||
| ax.bar(["L1 cache", "L2 cache", "L3 cache", "RAM", "SSD"], | ||
| [32, 1_000, 32_000, 16_000_000, 512_000_000]) | ||
| ax.set_yscale('log', base=2) | ||
| ax.set_yticks([1, 2**10, 2**20, 2**30], labels=['kB', 'MB', 'GB', 'TB']) | ||
| ax.set_title("Typical memory sizes") | ||
| ax.yaxis.grid() | ||
| # %% | ||
| # Dealing with negative values | ||
| # ---------------------------- | ||
| # Non-positive values cannot be displayed on a log scale. The scale has two options | ||
| # to handle these. Either mask the values so that they are ignored, or clip them | ||
| # to a small positive value. Which one is more suited depends on the type of the | ||
| # data and the visualization. | ||
| # | ||
| # The following example contains errorbars going negative. If we mask these values, | ||
| # the bar vanishes, which is not desirable. In contrast, clipping makes the value | ||
| # small positive (but well below the used scale) so that the error bar is drawn | ||
| # to the edge of the Axes. | ||
| x = np.linspace(0.0, 2.0, 10) | ||
| y = 10**x | ||
| yerr = 1.75 + 0.75*y | ||
| fig, (ax1, ax2) = plt.subplots(1, 2, layout="constrained", figsize=(6, 3)) | ||
| fig.suptitle("errorbars going negative") | ||
| ax1.set_yscale("log", nonpositive='mask') | ||
| ax1.set_title('nonpositive="mask"') | ||
| ax1.errorbar(x, y, yerr=yerr, fmt='o', capsize=5) | ||
| ax2.set_yscale("log", nonpositive='clip') | ||
| ax2.set_title('nonpositive="clip"') | ||
| ax2.errorbar(x, y, yerr=yerr, fmt='o', capsize=5) | ||
| plt.show() |
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.