Skip to content

3D Stem Plot #6271

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

Closed
wants to merge 8 commits into from
Closed

3D Stem Plot #6271

wants to merge 8 commits into from

Conversation

srihitha09
Copy link
Contributor

This PR implements 3D Stem Plots.

Hi! We are a team of five students at the University of Toronto. As a part of our course requirements, we have implemented a new feature for mpl - 3D Stem Plots. We think this feature is useful because it will allow users to create models for more complex data (e.g. Stem plots can be used to track particle motion by providing z axis information).

We tested our implementation and are able to produce most of the graphs in this link from MATLAB: http://www.mathworks.com/help/matlab/ref/stem3.html

Note: Due to time constraints, we decided to implement this function so that it requires 3 mandatory arguments: x, y, and z, which are arrays of the same length.

We have included a demo file to demonstrate how our function works. For example, examples/mplot3d/stem3_demo.py contains the following script:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as pet
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(0, 2*np.pi)
x = np.cos(theta)
y = np.sin(theta)
z = theta
markerline, stemlines, baseline = ax.stem3(x,y,z)

plt.show()

Running this script will produce the following graph:

screen shot 2016-04-05 at 5 34 00 pm

@samriddhikaushik @KanwarGill @zqliang @alveejamal

@QuLogic
Copy link
Member

QuLogic commented Apr 6, 2016

Please check the PEP8 build for the PEP8 issues that need to be fixed.

@WeatherGod
Copy link
Member

This is very interesting, and I like how it comes with unit tests, examples, and documentation. There are some issues that will need to be resolved first, but this is a neat first step.

First, do fix the PEP8 issues. Second, please follow the naming conventions of the other functions. "stem3" does not follow that convention. Third, the art3d module has juggle_axes() that might help you with reorganizing the x/y/z data based on zdir. We use it for contourf and such for similar reasons.

Fourth, this will need a "whats_new" entry.

Fifth, and it might not be able to get addressed this time around. Because of the way you build the StemContainer, and because of an inherent limitation of mplot3d, there are what I call "Escher Effects" in the plot. Look closely at the red circle in your example. It appears to be in front of all the stems. This could probably be partly mitigated by constructing the baseline first, then the stems.

@samriddhikaushik
Copy link
Contributor

samriddhikaushik commented Apr 6, 2016

@WeatherGod Thanks for reviewing our changes! We have updated our code to address most of the changes you suggested, including the pep8 issues, naming conventions, whats_new entry, and the "Escher Effects".

Re Escher Effects: We've modified the code so that the baselines are drawn before the stem lines, and it seems to have improved the image somewhat.

Re juggle_axes(): Our team will review the use of juggle_axes() to see how we can use it in stem.

We expect to have the changes committed sometime after the 18th (due to exams!). We hope that's alright.

@WeatherGod
Copy link
Member

No problem. This wouldn't be able to go in until version 2.1 anyway. Feel free to push up any updates you have so far so that we can comment on it. At the end, we will likely need to do a squash rebase so that we don't have multiple commits of the baseline images.

@WeatherGod WeatherGod added this to the 2.1 (next point release) milestone Apr 6, 2016
@samriddhikaushik
Copy link
Contributor

samriddhikaushik commented Apr 23, 2016

@WeatherGod Hi again. Our team has made a few commits to address your suggestions from before. We have made the following changes:

  1. Refactored our 3D stem function so that it makes use of juggle_axes (we updated a few of our tests to reflect the change in logic; e.g. our function no longer requires a rotate paramater - providing a value for zdir suffices)
  2. Changed the name of stem3() to stem() in order to follow mpl's naming conventions
  3. Added an entry for 3D stem in whats_new.rst
  4. Fixed the pep8 issues
  5. Modified the order in which the baselines, stemlines, and markerlines are created so that the "Escher Effects" are somewhat reduced. Here is the image of the graph produced by stem3d_demo.py.

stem3_demo

Here is the original image (for reference):
stem3_demo_prev

We have updated all relevant demos, unit tests, and docstrings as a result of these modifications. Please review our changes when you get the chance. Thanks once again for your suggestions!

#plot the baseline in the appropriate plane
for i in range(len(x)-1):

baseline, = Axes.plot(self, [x[i], x[i+1]], [y[i], y[i+1]],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probabyl better to use a LineCollection here. Or at least directly create artist.Line2D.

You should also set the color here to eliminate the need for the setp calls in your examples and tests.

@tacaswell tacaswell modified the milestone: 2.1 (next point release) Aug 29, 2017
@jklymak
Copy link
Member

jklymak commented Jul 14, 2020

This looks to be an abandoned student project, but if someone wanted to take it up, it looks like it is mostly done....

@jklymak jklymak added Good first issue Open a pull request against these issues if there are no active ones! status: orphaned PR labels Jul 14, 2020
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Aug 21, 2020
These are somewhat like the original tests in matplotlib#6271, but consolidated
into fewer images, and testing more properties.
@QuLogic QuLogic mentioned this pull request Aug 21, 2020
5 tasks
@QuLogic
Copy link
Member

QuLogic commented Aug 21, 2020

This is too old to push a rebase or further work; I've done so in a new PR #18310.

@jklymak jklymak closed this Aug 21, 2020
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Sep 3, 2020
These are somewhat like the original tests in matplotlib#6271, but consolidated
into fewer images, and testing more properties.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Sep 16, 2020
These are somewhat like the original tests in matplotlib#6271, but consolidated
into fewer images, and testing more properties.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Oct 3, 2020
These are somewhat like the original tests in matplotlib#6271, but consolidated
into fewer images, and testing more properties.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Oct 5, 2020
These are somewhat like the original tests in matplotlib#6271, but consolidated
into fewer images, and testing more properties.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Oct 9, 2020
These are somewhat like the original tests in matplotlib#6271, but consolidated
into fewer images, and testing more properties.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Nov 24, 2020
These are somewhat like the original tests in matplotlib#6271, but consolidated
into a single image, and testing more properties.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Dec 19, 2020
These are somewhat like the original tests in matplotlib#6271, but consolidated
into a single image, and testing more properties.
@QuLogic QuLogic added status: duplicate and removed Good first issue Open a pull request against these issues if there are no active ones! labels Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants