-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Removed unnecessary origin keywords #26608
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
timhoffm
merged 9 commits into
matplotlib:main
from
gautamsagar99:gautamsagar99/contourf-origin#26600
Aug 31, 2023
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0aaeb7
Removed unnecessary origin keywords
gautamsagar99 6fcdd63
Merge branch 'matplotlib:main' into gautamsagar99/contourf-origin#26600
gautamsagar99 3525d30
Added Contourf example using origin
gautamsagar99 cd74288
Build the documentation for Contourf_demo.py
gautamsagar99 6bd68f5
Modified Documentation for Contourf_demo.py
gautamsagar99 cf7afd7
Optimized the documentation for Contourf_demo.py
gautamsagar99 0e1a587
Modified documentation for Contourf_demo.py
gautamsagar99 9deecdd
Enhanced documentation for Contourf_demo.py
gautamsagar99 4185323
Final Enhancement in documentation for Contourf_demo.py
gautamsagar99 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 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,8 +8,6 @@ | |||||||||||||||||||||||||||||||
import matplotlib.pyplot as plt | ||||||||||||||||||||||||||||||||
import numpy as np | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
origin = 'lower' | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
delta = 0.025 | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
x = y = np.arange(-3.0, 3.01, delta) | ||||||||||||||||||||||||||||||||
|
@@ -41,14 +39,14 @@ | |||||||||||||||||||||||||||||||
# for purposes of illustration. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
fig1, ax2 = plt.subplots(layout='constrained') | ||||||||||||||||||||||||||||||||
CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin=origin) | ||||||||||||||||||||||||||||||||
CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
# Note that in the following, we explicitly pass in a subset of the contour | ||||||||||||||||||||||||||||||||
# levels used for the filled contours. Alternatively, we could pass in | ||||||||||||||||||||||||||||||||
# additional levels to provide extra resolution, or leave out the *levels* | ||||||||||||||||||||||||||||||||
# keyword argument to use all of the original levels. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
CS2 = ax2.contour(CS, levels=CS.levels[::2], colors='r', origin=origin) | ||||||||||||||||||||||||||||||||
CS2 = ax2.contour(CS, levels=CS.levels[::2], colors='r') | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
ax2.set_title('Nonsense (3 masked regions)') | ||||||||||||||||||||||||||||||||
ax2.set_xlabel('word length anomaly') | ||||||||||||||||||||||||||||||||
|
@@ -68,20 +66,14 @@ | |||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
fig2, ax2 = plt.subplots(layout='constrained') | ||||||||||||||||||||||||||||||||
levels = [-1.5, -1, -0.5, 0, 0.5, 1] | ||||||||||||||||||||||||||||||||
CS3 = ax2.contourf(X, Y, Z, levels, | ||||||||||||||||||||||||||||||||
colors=('r', 'g', 'b'), | ||||||||||||||||||||||||||||||||
origin=origin, | ||||||||||||||||||||||||||||||||
extend='both') | ||||||||||||||||||||||||||||||||
CS3 = ax2.contourf(X, Y, Z, levels, colors=('r', 'g', 'b'), extend='both') | ||||||||||||||||||||||||||||||||
# Our data range extends outside the range of levels; make | ||||||||||||||||||||||||||||||||
# data below the lowest contour level yellow, and above the | ||||||||||||||||||||||||||||||||
# highest level cyan: | ||||||||||||||||||||||||||||||||
CS3.cmap.set_under('yellow') | ||||||||||||||||||||||||||||||||
CS3.cmap.set_over('cyan') | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
CS4 = ax2.contour(X, Y, Z, levels, | ||||||||||||||||||||||||||||||||
colors=('k',), | ||||||||||||||||||||||||||||||||
linewidths=(3,), | ||||||||||||||||||||||||||||||||
origin=origin) | ||||||||||||||||||||||||||||||||
CS4 = ax2.contour(X, Y, Z, levels, colors=('k',), linewidths=(3,)) | ||||||||||||||||||||||||||||||||
ax2.set_title('Listed colors (3 masked regions)') | ||||||||||||||||||||||||||||||||
ax2.clabel(CS4, fmt='%2.1f', colors='w', fontsize=14) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
@@ -104,13 +96,36 @@ | |||||||||||||||||||||||||||||||
fig, axs = plt.subplots(2, 2, layout="constrained") | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
for ax, extend in zip(axs.flat, extends): | ||||||||||||||||||||||||||||||||
cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend, origin=origin) | ||||||||||||||||||||||||||||||||
cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend) | ||||||||||||||||||||||||||||||||
fig.colorbar(cs, ax=ax, shrink=0.9) | ||||||||||||||||||||||||||||||||
ax.set_title("extend = %s" % extend) | ||||||||||||||||||||||||||||||||
ax.locator_params(nbins=4) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
plt.show() | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
# %% | ||||||||||||||||||||||||||||||||
# Customizing Contour Plots with the origin Keyword | ||||||||||||||||||||||||||||||||
# ------------------------------------------------- | ||||||||||||||||||||||||||||||||
# This code showcases contour plot customization using the origin keyword, | ||||||||||||||||||||||||||||||||
# demonstrating distinct upper and lower origin perspectives. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
x = np.arange(1, 10) | ||||||||||||||||||||||||||||||||
y = x.reshape(-1, 1) | ||||||||||||||||||||||||||||||||
h = x * y | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
fig, (ax1, ax2) = plt.subplots(ncols=2) | ||||||||||||||||||||||||||||||||
# Note: lower and upper are the values provided | ||||||||||||||||||||||||||||||||
# to origin argument in contourf. | ||||||||||||||||||||||||||||||||
for (ax, origin) in [(ax1, 'upper'), (ax2, 'lower')]: | ||||||||||||||||||||||||||||||||
ax.set_title(f"origin={origin}") | ||||||||||||||||||||||||||||||||
cs = ax.contourf(h, levels=[10, 30, 50], colors=[ | ||||||||||||||||||||||||||||||||
'#808080', '#A0A0A0', '#C0C0C0'], extend='both', origin=origin) | ||||||||||||||||||||||||||||||||
cs.cmap.set_over('red') | ||||||||||||||||||||||||||||||||
cs.cmap.set_under('blue') | ||||||||||||||||||||||||||||||||
cs.changed() | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify this to:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This look more optimized. Thanks, Let me add it. |
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
plt.show() | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
# %% | ||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||
# .. admonition:: References | ||||||||||||||||||||||||||||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our convention is Title case - first word in title upper case, everything else lower case.
Also origin isn't a customization , it's a tell Matplotlib my data needs to be read from the lower left or upper left corner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@story645 Thank you for sharing. I will update the changes and push it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi, changes aren't showing up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh is it, Let me recommit and push the latest changes again.