简体   繁体   English

Matplotlib:在线的边缘上绘制标记

[英]Matplotlib: plotting marker on edge of line

I want to plot some data, but instead of having the marker centered on the line, I need to have the lower vertex of the triangle aligned with the line. 我想绘制一些数据,但是要使标记不在直线的中心,我需要使三角形的下顶点与直线对齐。 How can this be done? 如何才能做到这一点?

Here is my MWE: 这是我的MWE:

import matplotlib.pyplot as mplt

data = [1.]*10

mplt.plot(data, 'rv-' )
mplt.show()

Cheers, Jorge 干杯,豪尔赫

One way to achieve this is to use a special set of markers defined in matplotlib : 实现此目的的一种方法是使用在matplotlib 定义的一组特殊标记:

import matplotlib.pyplot as mplt
from matplotlib.markers import CARETDOWN

data = [1.]*10

mplt.plot(data, 'r-')
mplt.scatter(range(10), data, marker=CARETDOWN, facecolor='r')
mplt.show()

Unfortunately, it doesn't render into a triangle as clear as the one in the OP for me. 不幸的是,对我来说,它没有像OP中那样清晰地呈现为三角形。 If you're aiming for more visulal clarity, perhaps writing something along the lines of answers to this SO question would be a better option. 如果您希望更加直观地了解视觉效果,那么也许可以按照此SO问题的答案写一些东西, 是一个更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM