简体   繁体   English

绘制带有突出显示数据点的折线图?

[英]Plotting line graph with highlighted data points?

How can I use matplotlib or any other library to draw line graphs in Python with highlighted/prominent data points, something like the one shown in the image?如何使用 matplotlib 或任何其他库在 Python 中绘制带有突出显示/突出数据点的折线图,类似于图像中显示的数据点? 在此处输入图片说明

It might be worth while to just plot each point separately as a different color!将每个点分别绘制为不同的颜色可能是值得的!

Something like this maybe:可能是这样的:

import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [1,2,3,4,5]
plt.plot(x,y, 'bo-')
plt.plot(x[1],y[1], 'r*')
plt.show()

You can create two plots, one for your main data, and the other, with the prominent data points:您可以创建两个图,一个用于主数据,另一个用于突出数据点:

import matplotlib.pyplot as plt
#example data below:
main_data = [[45, 23, 13, 4, 5, 66], [33, 23, 4, 23, 5, 56]]
highlight = [[46, 42], [34, 10]]
plt.plot(*main_data)
plt.scatter(*highlight, marker='v', color='r')

在此处输入图片说明

I came here because I had a list of the x and y values and was creating a line graph out of it in matplotlib .我来到这里是因为我有一个 x 和 y 值的列表,并在matplotlib创建了一个折线图。 I simply want the data points to be highlighted as they are in the graph the question shows.我只想突出显示数据点,因为它们在问题显示的图表中。 The other posts don't give an answer to this.其他帖子没有给出答案。

I was able to solve it by simply adding the marker parameter to the plt.plot statement:我能够通过简单地将标记参数添加到plt.plot语句来解决它:

plt.plot(x_values, y_values, marker='o')

PS My post is not to answer the OP's question but rather to help anybody else who arrives at this question with the same doubt as me.... PS我的帖子不是要回答OP的问题,而是要帮助与我有同样疑问的任何其他人遇到这个问题....

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

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