You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the example scatter_piecharts.py, segments of the unit disk are approximated through polygons and used as markers. By chance, each segment has a coordinate with modulus 1, so that it is not rescaled. As soon as one starts to play with the example a bit, e.g. changing the proportions of the first two segments into
r1 = 0.1
r2 = r1 + 0.05
the second, green segment is rescaled, which it should not be for our purposes.
To counter that effect, one needs to apply a segment-specific scale, as is done here:
The resulting code looks like this (there's probably a nicer waying of writing this):
"""This example makes custom 'pie charts' as the markers for a scatter plotquThanks to Manuel Metz for the example"""importmathimportnumpyasnpimportmatplotlib.pyplotasplt# first define the ratiosr1=0.2# 20%r2=r1+0.4# 40%# define some sizes of the scatter markersizes= [60,80,120]
# calculate the points of the first pie marker## these are just the origin (0,0) +# some points on a circle cos,sinx= [0] +np.cos(np.linspace(0, 2*math.pi*r1, 10)).tolist()
y= [0] +np.sin(np.linspace(0, 2*math.pi*r1, 10)).tolist()
xy1=list(zip(x,y))
s1=max(max(x),max(y))
# ...x= [0] +np.cos(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist()
y= [0] +np.sin(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist()
xy2=list(zip(x,y))
s2=max(max(x),max(y))
x= [0] +np.cos(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist()
y= [0] +np.sin(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist()
xy3=list(zip(x,y))
s3=max(max(x),max(y))
fig, ax=plt.subplots()
ax.scatter( np.arange(3), np.arange(3), marker=(xy1,0),
s=[ s1*s1*xforxinsizes ], facecolor='blue' )
ax.scatter( np.arange(3), np.arange(3), marker=(xy2,0),
s=[ s2*s2*xforxinsizes ], facecolor='green' )
ax.scatter( np.arange(3), np.arange(3), marker=(xy3,0),
s=[ s3*s3*xforxinsizes ], facecolor='red' )
plt.show()
The text was updated successfully, but these errors were encountered:
In the example scatter_piecharts.py, segments of the unit disk are approximated through polygons and used as markers. By chance, each segment has a coordinate with modulus 1, so that it is not rescaled. As soon as one starts to play with the example a bit, e.g. changing the proportions of the first two segments into
the second, green segment is rescaled, which it should not be for our purposes.
To counter that effect, one needs to apply a segment-specific scale, as is done here:
The resulting code looks like this (there's probably a nicer waying of writing this):
The text was updated successfully, but these errors were encountered: