Skip to content
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

Matplotlib is currently used in a hybrid way (explicit vs. implicit interfaces) #319

Closed
mkcor opened this issue Dec 19, 2023 · 4 comments · Fixed by #321
Closed

Matplotlib is currently used in a hybrid way (explicit vs. implicit interfaces) #319

mkcor opened this issue Dec 19, 2023 · 4 comments · Fixed by #321
Labels
help wanted Looking for Contributors type:clarification Suggest change for make lesson clearer type:enhancement Propose enhancement to the lesson

Comments

@mkcor
Copy link
Contributor

mkcor commented Dec 19, 2023

Reference: https://matplotlib.org/stable/users/explain/quick_start.html#the-explicit-and-the-implicit-interfaces

I believe that we should use the "object-oriented (OO) style" throughout the lesson, since we have created figure and axis objects. At the moment, we are mixing up the OO-style with the pyplot-style. For instance, 328d544 adds figure and axis objects, but we still have all the pyplot-style legacy. I would change, e.g.,

fig, ax = plt.subplots()
plt.plot(bin_edges[0:-1], histogram)
plt.title("Grayscale Histogram")
plt.xlabel("grayscale value")
plt.ylabel("pixels")
plt.xlim(0, 1.0)

into

fig, ax = plt.subplots()
ax.plot(bin_edges[0:-1], histogram)
ax.set_title("Grayscale Histogram")
ax.set_xlabel("grayscale value")
ax.set_ylabel("pixels")
ax.set_xlim(0, 1.0);

/cc @datacarpentry/image-processing-curriculum-maintainers

Originally posted by @mkcor in #316 (comment)

@quist00
Copy link
Contributor

quist00 commented Dec 19, 2023

I would personally favor this change for several reasons, but I would like it to be something the curriculum advisory committee encourage for the carpentries as a whole rather than just this lesson. As @JeremyPike surmised, that line was originally added as a hack to eliminate the need to scroll to the top of the jupyter file every time you displayed a new image. Perhaps there is another way to accomplish that without using an oo style line, and retain the r-style if that is what the CAC ultimately favored.

I think during the move to beta we assumed this was like a 201 level carpentries workshop building on what they learned previously, so retaining the ggplot style they likely learned from more introductory carpentries workshops would be a good thing as it eliminates some cognitive load as they grapple with many other new concepts. New learners might also feel like they are just being asked to unlearn what they just learned.

I assume the introductory lessons adopt the ggplot approach because it is seen as slightly less complicated, especially for a subset that used ggplot with R, but I think front loading them with a little bit more will be worth it in the long run because I always encourage workshop attendees to use https://matplotlib.org/stable/gallery/ as a means to jumpstart their own plotting, and it relies almost exclusively on oo method when it is not using SNS or some other wrapper library.

@uschille
Copy link
Contributor

I believe that we should use the "object-oriented (OO) style" throughout the lesson, since we have created figure and axis objects. At the moment, we are mixing up the OO-style with the pyplot-style. For instance, 328d544 adds figure and axis objects, but we still have all the pyplot-style legacy. I would change, e.g.,

I personally would also favor @mkcor's suggestion. I think the current mix-up is due to the history of the lesson. Originally, the lesson used pyplot-style but when we transitioned to using Jupyter notebooks with %matplotlib widget it became necessary to create fig and ax objects for each cell. On that note, when I recently taught the lesson, I realized that %matplotlib widget does not suit certain platforms including Google Colab and Spyder. I intend to investigate alternatives when I find time.

@tobyhodges
Copy link
Member

It seems we have (lazy) consensus and I would welcome a PR to address this across all episodes, whether from @mkcor or anyone else reading this who is willing to take the time.

@uschille please let us know what you discover regarding %matplotlib widget. Perhaps a good discussion point at a Maintainer call soon?

@mkcor
Copy link
Contributor Author

mkcor commented Feb 29, 2024

@GParolini could help out with this issue (see scikit-image/scikit-image#7330 (comment)). Many thanks to her!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Looking for Contributors type:clarification Suggest change for make lesson clearer type:enhancement Propose enhancement to the lesson
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants