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

negative polar values #2133

Closed
tacaswell opened this issue Jun 18, 2013 · 4 comments
Closed

negative polar values #2133

tacaswell opened this issue Jun 18, 2013 · 4 comments

Comments

@tacaswell
Copy link
Member

A issue raised in this (http://stackoverflow.com/questions/17154006/pyplot-polar-scatter-plot-color-for-sign) SO question, the way that polar plots handles negative numbers changed between 1.2.0 and 1.2.1.

If this is an un-intentional change, should probably be fixed before 1.3.0.

maybe related to #1603

@joferkington
Copy link
Contributor

Just as a simple example of the change:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')

theta = [0, np.pi/2]
ax.plot(theta, [0.5, 0.5], 'ro')
ax.plot(theta, [-0.5, -0.5], 'go')

plt.show()

With v1.2.0 and earlier, the above example results in:

image

With 1.2.1 (and the current git head):

figure_1

As a simple test for the behavior:

from matplotlib.projections import PolarAxes
import numpy as np

trans = PolarAxes.PolarTransform()
result = trans.transform_point([0, -1])
assert not all(np.isnan(result))

As @tacaswell mentioned, this is a result of #1603. That bugfix would seem to indicate that "reflecting" negative radius values to the opposite direction was never supposed to be the intended behavior. However, it's how polar plots have worked in matplotlib for quite some time.

Which one is the "correct" behavior?

@dmcdougall
Copy link
Member

I've been thinking about this for a few days now, and I have come to the conclusion that v1.2.1 fixed a long-standing bug with how negative radii were handled. Any time I've used polar coordinates the radius was always positive and if you wanted points in the opposite direction you must change the theta variable. That said, there's certainly an argument to be made for the flexibility of being able to reflect points easily by flipping a sign.

From Wikipedia:

Where a unique representation is needed for any point, it is usual to limit r to
non-negative numbers (r ≥ 0) and φ to the interval [0, 360°) or (−180°, 180°] (in radians,
[0, 2π) or (−π, π]).

For that reason, I think I'm going to close this. If anybody would like to reopen to continue discussion, please feel free to do so.

@Shooter23
Copy link

https://en.wikipedia.org/wiki/Polar_coordinate_system

Under "Uniqueness of polar coordinates":

"Similarly, any polar coordinate is identical to the coordinate with the negative radial component and the opposite direction (adding 180° to the polar angle)."

This suggests that the original behavior was correct.

@timhoffm
Copy link
Member

That is true if you really want to plot polar coordinates (which also implies you always have to start from 0 radius in the center). Even though the projection is called 'polar', this radial plot has a broader scope in which negative values may actually exist at certain angles and are not equivalent to the absolute value rotated by 180 degrees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants