-
Notifications
You must be signed in to change notification settings - Fork 5
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
Hotfix contour #24
Hotfix contour #24
Conversation
88dd1b3
to
f2bf756
Compare
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.
The PR that added this bit of code is #17.
The diff there removed this block of code:
for contour in obj.collections:
contour.set_linestyle("-")
contour.set_linewidth(linewidth)
contour.set_edgecolor("face")
Presumably one needs something to set how the contours are drawn. I don't see how simply removing the offending code is actually fixing anything.
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.
From my understanding, the collections
property used to hold the lines for the different levels. This property is removed and you can now access the lines directly using get_paths
which returns flat list of all the paths for all the levels. If I look at the api (here), the draw command sets the properties for the paths manually which makes the collections
part redundant. Why? well my initial impulse would be to replace the collections with a similar command for the paths, but the api is already doing that on draw -- hence the removal.
OK. Let's add a test against an older version of the code to ensure a plot that accesses these features comes out the same. |
I went back to proplot and copied the tests -- for which many won't work -- to recreate the contour which generated: I think, however, that this is wrong. The reason why I think this is that the contour shows high and lows, but the linestyles do not reflect these differences. The current unittests will produce
producing Digging a bit further, I went to the proplot docs to look for some tests. From the proplot docs I can generate the following figure using this
Which "looks" the same as on their docs. Conclusion:I think the current implementation correctly implements the contour that matplotlib intends, and prior versions of proplot do not. I propose to set the baseline for this particular plot at the current version rather to check it further back. But I am open if someone has the time or gusto to check it with even older versions. SubnoteI used the latest official build from proplot, with matplotlib 3.4.3 and manually rebuilding basemap -- I can share the env if one needs it. |
I don't follow your message at all. In the plot from the current unittests, the right-hand subplot looks really funky. The black contour lines only show when there is a contour label. This is fixed by the extra call specified and the fixed plot looks like the output from proplot previously. I think we should include this call in the code so that the behavior is unchanged. Proplot deviates from matplotlib on purpose to produce better defaults and nicer plots. IDK why we would change that. |
The unittest situation you mentioned - those were actually brought over from Ulraplot since Proplot didn't have any tests to begin with. Most of these unittests fail under proplot as they include changes from a newer matplotlib, making retroactive testing and generaing baselines hard -- unless we fix proplot (or the tests). This makes it hard to include a test that generates baselines without retroactively fixing proplot -- which I don't feel like is necessary as I will show next. I've thoroughly checked the contour plotting and can confirm it's working properly. The main difference you're seeing is just in how the default styles work:
The good news is you can still recreate those proplot-style images exactly like before. The changes are really just about giving users better default options out of the box. This means that the proposed change itself, does not remove features or causes issue since we can recreate issues. The only thing we could consider is whether we want the default dashed line behavior or not. Hopefully this clears the issues up! |
Can you send me the code that made the second plot above? That would help me understand what is going on. |
import ultraplot as uplt
import numpy as np
state = np.random.RandomState(51423)
data = state.rand(5, 5) * 10 - 5
fig, axs = uplt.subplots(ncols=2)
ax = axs[0]
ax.contourf(
data,
edgecolor="k",
linewidth=1.5,
labels=True,
labels_kw={"color": "k", "size": "large"},
)
ax = axs[1]
m = ax.contourf(data, ls = '-', lw = 1.5, edgecolor = 'k')
ax.clabel(m, colors="black", fontsize="large") # looks finewithout this
import matplotlib.patheffects as pe
m.set_path_effects([pe.Stroke(linewidth=1.5, foreground="k), pe.Normal()])
uplt.show(block = 1) |
Note it is from the unittest ;-)! |
Ah can you send a link to the unittest code? |
ultraplot/ultraplot/tests/test_2dplots.py Line 106 in 46616ab
|
I am merging this with devel. After locally testing the open PRs it all looks good for now. |
is that ok @beckermr? |
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.
Sorry for the delay here. One question about the python bound but otherwise LGTM.
pyproject.toml
Outdated
@@ -19,14 +19,13 @@ maintainers = [ | |||
] | |||
description = "A succinct matplotlib wrapper for making beautiful, publication-quality graphics." | |||
readme = "README.rst" | |||
requires-python = ">=3.6.0" | |||
requires-python = ">=3.8, <3.12" |
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.
Why the upper bound here?
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.
basemap won't install for python>=3.12. Eventhough we don't have a hard requirement for it some of the tests will fail. I contacted the people from basemap and they are working on a fix. I put a crude PR up there that monkey patches basemap for these higher versions, but it isn't (and will likely never be) merged.
I checked the code with this monkey patch for basemap and ultraplot will pass all the tests for these higher versions.
Feel free to merge to main if you'd like. |
Addresses #23 partly reverts #13