I would like to plot a scatter of values distances from mean in a scatter plot.
Here is my code for this:
import numpy as np
import matplotlib.pyplot as plt
x=[5,6,2,6,9]
y=[2,4,5,1,10]
x_mean=np.mean(x)
y_mean=np.mean(y)
x_dist_mean=x-x_mean
y_dist_mean=y-y_mean
my labels=['horse', 'cat' , 'dog', 'fish', 'ape']
plt.scatter(x_dist_mean, y_dist_mean ,alpha=0.5 )
plt.show()
However, I would like to have the dots in the scatter proportional in size for the distance from mean, so a large distance would give a big circle and a small distance would give a small circle. In addition I would also like to color the circles with the label names in my_labels.
Could someone help me with this?
Just pass in the s
parameter for the sizes of the dots and later annotate the dots. You can play with the annotate function a lot more. (I just placed the labels to start at the center of the dot, but you can make it look different...)
import numpy as np
import matplotlib.pyplot as plt
x=[5,6,2,6,9]
y=[2,4,5,1,10]
x_mean = np.mean(x)
y_mean = np.mean(y)
x_dist_mean = x - x_mean
y_dist_mean = y - y_mean
size = np.abs(x_dist_mean * y_dist_mean) * 100
labels=['horse', 'cat' , 'dog', 'fish', 'ape']
plt.scatter(x_dist_mean, y_dist_mean, s=size, alpha=0.5, label=labels)
for label, x, y in zip(labels, x_dist_mean, y_dist_mean):
plt.annotate(label, xy = (x, y))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다