【问题标题】:Simple ellipse on chart (pyplot, k-means Coursera course)图表上的简单椭圆(pyplot、k-means Coursera 课程)
【发布时间】:2020-06-25 01:22:00
【问题描述】:

我目前正在学习我的第一门 Coursera 数据科学课程 (K-Means)。我几乎所有事情都做得很好,但被困在一个简单的任务上。在我的“簇”上绘制两个椭圆以突出“质心”到它的 STD 的距离。

一定是愚蠢的,但我浏览了谷歌和课程本身,但没有运气。

代码(我知道很业余)和它生成的情节如下。

plt.figure(figsize=(8, 8))
plt.title('Cluster Segregtion')
plt.scatter(c0['V1n'], c0['V2n'], color = 'blue', s = 30 , alpha = 0.5)
plt.scatter(c1['V1n'], c1['V2n'], color = 'red', s = 30 , alpha = 0.5)
plt.scatter(clusters[:,0], clusters[:,1], color = 'orange', s = 40000, alpha = 0.3)

谁能给我一个简单的椭圆代码?

最好的问候 FC

【问题讨论】:

标签: python-3.x matplotlib plot


【解决方案1】:

您可以使用 matplotlib 的补丁模块。例如(一些编造的数字):

from matplotlib.patches import Ellipse
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1)
ax.scatter([2,4,6,3,4,5,4,], [1,8,9,3,9,7,2,]) 
patch = Ellipse((4,5), width=9, height=3, angle=75, alpha=0.4, ls='solid', ec='g', fc = 'r', lw='2.')
ax.add_patch(patch)

不过,您可能希望从数据本身中找到坐标和角度,但这是一个单独的问题。您可以阅读有关补丁的 matplotlib 文档。

【讨论】:

  • 完美!非常感谢!
猜你喜欢
  • 1970-01-01
  • 2011-10-04
  • 2014-07-30
  • 1970-01-01
  • 1970-01-01
  • 2013-08-08
  • 2012-11-01
  • 1970-01-01
  • 2014-07-13
相关资源
最近更新 更多