matplotlib中从点到轴的虚线 [英] Dashed lines from points to axes in matplotlib

查看:26
本文介绍了matplotlib中从点到轴的虚线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组这样绘制的点:

I have a set of points which I am plotting like this:

import matplotlib.pyplot as plt`

x = [1,2,3,4,5,6]
y = [1,4,9,16,25,36]

plt.scatter(x, y)

plt.show()

这给出了这样的输出

我想要的是从点到轴垂直放置垂直线,如下图所示:

What I want is to drop perpendiculars from the points to the axes, like in the figure below:

如何实现?

推荐答案

使用 hlinesvlines 可以分别绘制水平线和垂直线.

Using hlines and vlines you can plot horizontal and vertical lines respectively.

import matplotlib.pyplot as plt

x = [1,2,3,4,5,6]
y = [1,4,9,16,25,36]

plt.vlines(x, 0, y, linestyle="dashed")
plt.hlines(y, 0, x, linestyle="dashed")
plt.scatter(x, y, zorder=2)

plt.xlim(0,None)
plt.ylim(0,None)
plt.show()

这篇关于matplotlib中从点到轴的虚线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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