-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed as not planned
Labels
status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.Issues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: confirmed bugstatus: inactiveMarked by the “Stale” Github ActionMarked by the “Stale” Github Actiontopic: polar
Milestone
Description
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?
Metadata
Metadata
Assignees
Labels
status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.Issues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: confirmed bugstatus: inactiveMarked by the “Stale” Github ActionMarked by the “Stale” Github Actiontopic: polar