I'm currently trying to plot an HSV legend, i.e. a circle of color that becomes white as the radius goes to 0. I also posted this question on stackoverflow in the hope of getting a clever workaround.
Code:
def complex_to_rgb(complex_data, invert=False):
from numpy import angle, max, pi, sin, zeros
phase = angle(complex_data)
amplitude = abs(complex_data)
amplitude = amplitude/max(max(amplitude))
A = zeros((complex_data.shape[0], complex_data.shape[1], 3))
A[:,:,0] = .5*(sin(phase)+1)*amplitude
A[:,:,1] = .5*(sin(phase+pi/2)+1)*amplitude
A[:,:,2] = .5*(-sin(phase)+1)*amplitude
if(invert):
return 1-A
else:
return A
import numpy as np
from matplotlib.pyplot import figure
N = 1024
x = np.linspace(-1, 1, N)
y = np.linspace(-1, 1, N)
X,Y = np.meshgrid(x,y)
R = np.sqrt(X*X + Y*Y)
PHI = np.arctan2(Y, X)
fig = figure()
ax = fig.add_subplot(111, polar=True)
ax.imshow(complex_to_rgb(R*np.exp(1j*PHI) * (R<1), invert=True))
ax.set_xticks([-.5, 0, np.pi/2, np.pi, 3*np.pi/2])#-.5)
ax.set_yticks([0, N/3, 2*N/3, N])
ax.set_xticklabels(['', '$0$', r'$\pi/2$', r'$\pi$', r'$3\pi/2$'])
ax.set_yticklabels([])
fig.show()
Problem is, if I change the -.5 xtick (e.g. to +.5), the plot gets messed up and I get division by zero warnings:
....\lib\site-packages\matplotlib\image.py:161: RuntimeWarning: divide by zero encountered in double_scalars
sy = dyintv/viewlim.height
....\lib\site-packages\matplotlib\image.py:190: RuntimeWarning: divide by zero encountered in double_scalars
sy = dyintv/viewlim.height
I don't want the -.5 arbitrary tick mark. Why does a tick mark influence the drawing of an image?
However I am not sure we claim to support polar axes + imshow. It looks like it does not warp the the image to polar coordinates and it is just happening to do the right thing.
As you say, it seems this bug has to do with how imshow does not work on polar axes. As the imshow appears to be ignored, the view limits are empty. Setting additional ticks triggers something that makes the view nonsingular.
Setting radial limits will fix the division issues, as will my PR at this time, but it doesn't yet fix the problem with imshow.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
tacaswell commented on Mar 20, 2014
That is odd.....
However I am not sure we claim to support polar axes + imshow. It looks like it does not warp the the image to polar coordinates and it is just happening to do the right thing.
tacaswell commented on Jul 17, 2015
@QuLogic As long as you are touching polar axes could you have a look at this bug as well?
BUG: Ensure polar radial limits are nonsingular.
BUG: Ensure polar radial limits are nonsingular.
QuLogic commented on Jul 21, 2015
As you say, it seems this bug has to do with how imshow does not work on polar axes. As the imshow appears to be ignored, the view limits are empty. Setting additional ticks triggers something that makes the view nonsingular.
Setting radial limits will fix the division issues, as will my PR at this time, but it doesn't yet fix the problem with imshow.
14 remaining items
BUG: Ensure polar radial limits are nonsingular.
BUG: Ensure polar radial limits are nonsingular.
BUG: Ensure polar radial limits are nonsingular.
BUG: Ensure polar radial limits are nonsingular.
BUG: Ensure polar radial limits are nonsingular.
BUG: Ensure polar radial limits are nonsingular.
BUG: Ensure polar radial limits are nonsingular.
BUG: Ensure polar radial limits are nonsingular.
tacaswell commented on Aug 11, 2020
I can no longer get this do do anything sensible on the current master..
github-actions commented on Mar 4, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!