Issue
Hey can someone help me?
I want to fill the area between the lines. I have two areas finished, but the other one, I don't know how I do that.
This is my code:
import numpy as np
import matplotlib.pyplot as plt
# Constellation:
M = 8
A = 1 # Amplitude
m = np.arange(0,M) #all information symbols m={0,1,...,M-1}
I = A*np.cos(m/M*2*np.pi)
Q = A*np.sin(m/M*2*np.pi)
constellation = I + 1j*Q #reference constellation
# Plotting the fig:
fig,ax = plt.subplots(figsize=[10,10])
ax.plot([-1/2,0],[-1,0],'k--')
ax.plot([1/2,0],[-1,0],'k--')
ax.plot([1/2,0],[1,0],'k--')
ax.plot([-1/2,0],[1,0],'k--')
ax.plot([-1,0],[-1/2,0],'k--')
ax.plot([1,0],[1/2,0],'k--')
ax.plot([-1,0],[1/2,0],'k--')
ax.plot([1,0],[-1/2,0],'k--')
plt.fill_between([0,-1], [0,-1/2],[0,1/2],color='gray',alpha=0.5)
plt.fill_between([0,1], [0,-1/2],[0,1/2],color='gray',alpha=0.5)
circle = plt.Circle((0,0),1,color='k',linestyle='--',fill=False)
ax.add_patch(circle)
ax.scatter(np.real(constellation),np.imag(constellation),c='c',s=20**2)
ax.set_xlabel(r'I-Axis $Real\{x\}$')
ax.set_ylabel(r'Q-Axis $Imag\{x\}$')
plt.tight_layout();
and this is my current output: Image
Thanks!
Solution
There is similar function fill_betweenx(y, x1, x2)
You can also use plt.fill(x, y)
to fill polygon
.
Doc: fill_betweenx(), fill()
import matplotlib.pyplot as plt
fig,ax = plt.subplots(figsize=[10,10])
ax.plot([-1/2,0],[-1,0],'k--')
ax.plot([1/2,0],[-1,0],'k--')
ax.plot([1/2,0],[1,0],'k--')
ax.plot([-1/2,0],[1,0],'k--')
ax.plot([-1,0],[-1/2,0],'k--')
ax.plot([1,0],[1/2,0],'k--')
ax.plot([-1,0],[1/2,0],'k--')
ax.plot([1,0],[-1/2,0],'k--')
plt.fill_between([0,-1], [0,-1/2],[0,1/2],color='gray',alpha=0.5)
plt.fill_between([0,1], [0,-1/2],[0,1/2],color='gray',alpha=0.5)
plt.fill_betweenx([0,-1],[0,-1/2],[0,1/2],color='green',alpha=0.5)
plt.fill_betweenx([0,1],[0,-1/2],[0,1/2],color='green',alpha=0.5)
plt.fill([-1, 0, -1/2], [-1/2, 0, -1], color='red',alpha=0.5)
plt.fill([1, 0, 1/2], [1/2, 0, 1], color='red',alpha=0.5)
plt.show()
Answered By - furas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.