Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot additional points on the top of scatter plot?

I have panda dataframe as df with two attributes df.one (=x) and df.two (=y). Now, I want to plot scatter plot for these data points. I used

ax1 = fig.add_subplot(111)
ax1.scatter(df.one,df.two,c = 'g',marker = 'o',alpha = 0.2)

Now, I want to plot centroid of the data points give by C. How should I overlay centroid on the above scatter plot? I tried:

ax1.scatter(C[:,0],C[:,1],c = 'r',marker = 'x')

But it overrides the scatter plot, I want to overlay on that. Is there any hold on option, similar to matlab?

like image 836
talos1904 Avatar asked Jun 12 '17 17:06

talos1904


2 Answers

If you need points overlaid on the original plot, use

ax.plot(x, y)

ex.

ax = plt.subplot(1, 1, 1)
ax.scatter([1, 2, 3], [1, 2, 3])
ax.plot(1.5, 1.5, "or")

enter image description here

if you pass a list to x and y, multiple points can be added to the plot. Also in case you need to add some annotation beside the point, try

ax.annotate("Some explanation", x, y)
like image 122
Bubble Bubble Bubble Gut Avatar answered Sep 29 '22 15:09

Bubble Bubble Bubble Gut


from matplotlib import pyplot as plt
from statistics import *

bill = [34.00, 108.00, 64.00, 88.00, 99.00, 51.00]
tip = [ 5.00,  17.00,  11.00, 8.00,  14.00, 5.00]

bill.sort()
tip.sort()

print(mean(bill))
print(mean(tip))
plt.scatter(bill, tip)
plt.scatter([mean(bill)], [mean(tip)])
plt.show()

I wanted to plot the mean of the data too, so I used this format and got this result:

Result of data

like image 32
Aryamaan Goswamy Avatar answered Sep 29 '22 14:09

Aryamaan Goswamy