matplotlib - scatter plot same point repeated several times python -
i trying draw scatter plot dictionary bellow:
data_dict = {12: [1, 17, 11, 17, 1, 14, 38], 13: [13, 6, 4, 6], 14: [15, 8, 20, 8, 7], 15: [2, 3, 3, 1], 16: [62, 13, 36, 3, 8, 99, 54], 17: [1], 18: [44, 30, 36, 14, 21, 13, 44, 1, 62, 36], 19: [5, 5], 20: [27, 42, 42, 18, 31, 55, 31, 55], 21: [59, 1, 42, 17, 66, 26, 18, 4, 36, 42, 20, 54, 44, 35]}
i using following code draw scatter plot dictionary keys x values values corresponding values.
for xe, ye in data_dict.iteritems(): plt.scatter([xe] * len(ye), ye)
and getting plot:
i'de able distinguish between having 1 point @ given x , y location vs having multiple point. example x = 12, y = 1 , 17 repeated twice. i'm looking in way of representing repetition either color or size of data points.
i not find reference on how this. appreciate or guidance.
thanks.
you can .count() each item , calculate size based off that, use named parameter s
specify sizes. btw change .items()
.iteritems()
if on python 2
import matplotlib.pyplot plt data_dict = {12: [1, 17, 11, 17, 1, 14, 38], 13: [13, 6, 4, 6], 14: [15, 8, 20, 8, 7], 15: [2, 3, 3, 1], 16: [62, 13, 36, 3, 8, 99, 54], 17: [1], 18: [44, 30, 36, 14, 21, 13, 44, 1, 62, 36], 19: [5, 5], 20: [27, 42, 42, 18, 31, 55, 31, 55], 21: [59, 1, 42, 17, 66, 26, 18, 4, 36, 42, 20, 54, 44, 35]} size_constant = 20 xe, ye in data_dict.items(): xaxis = [xe] * len(ye) #square amplify effect, if ye.count(num)*size_constant effect barely noticeable sizes = [ye.count(num)**2.5 * size_constant num in ye] plt.scatter(xaxis, ye, s=sizes) plt.show()
here's looks data more reptititions, since dataset doesn't have lot of repeats it's hard show effect.
data_dict = {5 : [1], 8 : [5,5,5], 11 : [3,3,3], 15 : [8,8,8,8,7,7], 19 : [12, 12, 12, 12, 12, 12]}
Comments
Post a Comment