Matplotlib 绘制虚线圆圈 [英] Matplotlib Plot Dashed Circles

查看:90
本文介绍了Matplotlib 绘制虚线圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于以下内容:

 将matplotlib.pyplot导入为plt将numpy导入为npx = np.random.randn(60)y = np.random.randn(60)x2 = np.random.randn(60)y2 = np.random.randn(60)plt.scatter(x,y,s = 80,facecolors ='none',edgecolors ='r')plt.scatter(x2,y2,s = 80,facecolors ='none',edgecolors ='r')plt.show()

我将如何仅针对 x 2 和 y2 用虚线圆圈绘制相同的数据(其中每个圆圈的轮廓是虚线而不是实线)?

提前致谢!

更新:我知道可以使用

对于该标记大小,我宁愿使用 linestyle =':'.

Given the following:

import matplotlib.pyplot as plt 
import numpy as np 

x = np.random.randn(60) 
y = np.random.randn(60)
x2 = np.random.randn(60)
y2 = np.random.randn(60)

plt.scatter(x, y, s=80, facecolors='none', edgecolors='r')
plt.scatter(x2, y2, s=80, facecolors='none', edgecolors='r')
plt.show()

How would I plot this same data with dashed circles instead (where the outline of each circle is dashed instead of solid) for x 2 and y2 only?

Thanks in advance!

Update: I know this can be done with patches as in here, but I need it to be done via plt.scatter if possible because I will also be plotting another set of circles on the same plot and using patches messed with the chart dimensions (was way too thin).

解决方案

Pass linestyle='--' to scatter.

plt.scatter(x, y, s=80, facecolors='none', edgecolors='r')
plt.scatter(x2, y2, s=80, facecolors='none', edgecolors='r',
            linestyle='--')

For that marker size I would rather use linestyle=':' though.

这篇关于Matplotlib 绘制虚线圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆