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

BUG fix: prevent 2D axis from showing up after calling Axes3D.cla() #4553

Merged
merged 2 commits into from Jun 25, 2015

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Jun 24, 2015

This fixes a bug in Axes3D where the call to .cla() erroneously results in a 2D axis being drawn.

To see the bug on current master, run the following code and note that a 2D rather than 3D axis is displayed

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

ax = plt.subplot(111, projection='3d')
a = np.random.rand(128, 3)
ax.scatter3D(a[:, 0], a[:, 1], a[:, 2], 'k.')
ax.set_axis_off()  #have to turn of the 3D axis to be able to see the 2D one introduced by cla()
ax.cla()
plt.show()

Here is a screenshot of the output of the above:
cla_bug

@WeatherGod
Copy link
Member

Good catch. Could you add an image test using the example?

@tacaswell tacaswell added this to the next point release milestone Jun 24, 2015
@tacaswell
Copy link
Member

👍 It is great when small changes fix big problems.

@grlee77
Copy link
Contributor Author

grlee77 commented Jun 24, 2015

@WeatherGod : I am unclear on what you mean by adding an "image test". where would this go? (I am new to matplotlib development)

@WeatherGod
Copy link
Member

This should explain what I mean: http://matplotlib.org/devel/testing.html#writing-a-simple-test

Tests for mplot3d are at lib/mpl_toolkits/tests/test_mplot3d.py

@tacaswell
Copy link
Member

You probably only need the png for this case.

@WeatherGod
Copy link
Member

I do find it interesting that fixing this required a change in the base Axes class. Usually, all of mplot3d's bugs are contained entirely within mplot3d...

@grlee77
Copy link
Contributor Author

grlee77 commented Jun 25, 2015

Yes, I had originally started to change the cla() method in the Axes3D object, but then realized that just changing that single line in the base class would do it!

I will add the test as suggested later today

@WeatherGod
Copy link
Member

python2.6 test failure looks like it is one of those intermittent errors. I restarted it.

WeatherGod added a commit that referenced this pull request Jun 25, 2015
BUG fix:  prevent 2D axis from showing up after calling Axes3D.cla()
@WeatherGod WeatherGod merged commit 44ee7f9 into matplotlib:master Jun 25, 2015
@WeatherGod
Copy link
Member

Thanks for the fix! I finally had a moment to look deeper into the problem, and it isn't so much that calling ax.cla() would generally result in a bad axes, but rather that Axes.cla() didn't reset all of the attributes needed because it was focused on explicitly resetting certain attributes (that only applied to 2d plots) rather than calling various functions that would have been extended in subclasses of Axes. If someone happened to change one of those attributes prior to calling ax.cla(), then that attribute wouldn't get reset.

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.

None yet

3 participants