在点与点之间填充数据 Matplotlib[关闭]。

问题描述 投票:-1回答:1

我开始使用Matplotlib,我需要重新创建一个图形,该图形可以是 X 从1到28.的图形。enter image description here

我怎么能用6个值来做这个图形,并填充中间的值?

python python-3.x numpy matplotlib
1个回答
1
投票

请插入 "精确 "的值在 x 答案 y

import matplotlib.pyplot as plt

# data, the length of the two lists MUST be the same 
x = [0, 6, 10, 15, 17, 26, 28] 
y = [0, 20, 20, 30, 30, 0, 0] 

# plot the data
plt.plot(x,y) 

# modify the ticks to show directly the values
plt.xticks(x) 
plt.yticks(sorted(set(y))) 

# make a grid
plt.grid(1)

# tell matplotlib "we are done, please show what we have prepared"
plt.show()                                                                    

enter image description here


1
投票

要从你的图像中读出准确的数值是相当困难的,你必须自己输入正确的数值。如果你有任何问题,请随时提问。

import matplotlib.pyplot as plt

x = [0, 6, 10, 15, 22, 26]
y = [0, 22, 22, 27.5, 27.5, 0]

# optional; making the y axis go up to 45
axes = plt.gca()
axes.set_ylim([0, 45])

plt.plot(x,y)
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.