Matplotllib plot scatter with circle sizes proportional from distance to mean

jonas

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?

Viktor Kerkez

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Different font sizes in python plot

분류에서Dev

Stata - Scatter plot confidence interval

분류에서Dev

Add an area to a scatter plot in Excel

분류에서Dev

Align scatter plot to right side in highcharts

분류에서Dev

ploting scatter plot with 2D list

분류에서Dev

Cannot Scatter, Plot, Show() In While Loop

분류에서Dev

How to give color to a class in scatter plot in R?

분류에서Dev

How can I overlay box plot on scatter plot in matlab or R?

분류에서Dev

Distance of a command from a shebang?

분류에서Dev

Color scatter plot in Matlab according to 0 or 1 value

분류에서Dev

Scatter Plot graphing excel VBA - wont graph my range of data

분류에서Dev

Zusammenführen von Count Plot und Mean in demselben Plot SNS

분류에서Dev

R universal distance between plot limits and axis labels/title

분류에서Dev

Circle detection from gray level image in MATLAB

분류에서Dev

make circle path start from top

분류에서Dev

How can i assign different colors to each dot in scatter plot using jfreechart in java?

분류에서Dev

How to plot multiple data sets on Matplotlib Axes3D scatter without deleting previous data?

분류에서Dev

How to add gradient color fill to the points of scatter plot using google Charts?

분류에서Dev

Creating a new vector, from 2 dataframes of different sizes

분류에서Dev

Can ffmpeg encode video from frames of different sizes?

분류에서Dev

How can I use the same ViewController from a storyboard with different sizes?

분류에서Dev

Proportional rounding error

분류에서Dev

how to calculate proportional ratio

분류에서Dev

compare vertical distance from the top of an element and scroll distance from top of the page

분류에서Dev

plot_ly scatter3d에 대해 1 대신 두 줄 추가

분류에서Dev

Altair 'Scatter Plot with Href'예제가 더 이상 작동하지 않습니까?

분류에서Dev

plt.scatter () 플롯은 Matplotlib의 plt.plot () 플롯처럼 작동합니다.

분류에서Dev

pandas df.plot.scatter는 실패하지만 df.plot은 플롯을 생성합니다.

분류에서Dev

Need intersect point for a line coming from center of circle?

Related 관련 기사

  1. 1

    Different font sizes in python plot

  2. 2

    Stata - Scatter plot confidence interval

  3. 3

    Add an area to a scatter plot in Excel

  4. 4

    Align scatter plot to right side in highcharts

  5. 5

    ploting scatter plot with 2D list

  6. 6

    Cannot Scatter, Plot, Show() In While Loop

  7. 7

    How to give color to a class in scatter plot in R?

  8. 8

    How can I overlay box plot on scatter plot in matlab or R?

  9. 9

    Distance of a command from a shebang?

  10. 10

    Color scatter plot in Matlab according to 0 or 1 value

  11. 11

    Scatter Plot graphing excel VBA - wont graph my range of data

  12. 12

    Zusammenführen von Count Plot und Mean in demselben Plot SNS

  13. 13

    R universal distance between plot limits and axis labels/title

  14. 14

    Circle detection from gray level image in MATLAB

  15. 15

    make circle path start from top

  16. 16

    How can i assign different colors to each dot in scatter plot using jfreechart in java?

  17. 17

    How to plot multiple data sets on Matplotlib Axes3D scatter without deleting previous data?

  18. 18

    How to add gradient color fill to the points of scatter plot using google Charts?

  19. 19

    Creating a new vector, from 2 dataframes of different sizes

  20. 20

    Can ffmpeg encode video from frames of different sizes?

  21. 21

    How can I use the same ViewController from a storyboard with different sizes?

  22. 22

    Proportional rounding error

  23. 23

    how to calculate proportional ratio

  24. 24

    compare vertical distance from the top of an element and scroll distance from top of the page

  25. 25

    plot_ly scatter3d에 대해 1 대신 두 줄 추가

  26. 26

    Altair 'Scatter Plot with Href'예제가 더 이상 작동하지 않습니까?

  27. 27

    plt.scatter () 플롯은 Matplotlib의 plt.plot () 플롯처럼 작동합니다.

  28. 28

    pandas df.plot.scatter는 실패하지만 df.plot은 플롯을 생성합니다.

  29. 29

    Need intersect point for a line coming from center of circle?

뜨겁다태그

보관