python绘制折线图
怎么把两个横坐标不一样的数据绘制在一起它们数据都不会并到一起,横坐标0.18407后面接着跟4.86334e-14了{:5_94:}
import re
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import MultipleLocator
def file_view(file): #这个是抓取目标数据的,和这个没有关系
x = []
y = []
p = re.compile(r'\s+')
q = re.compile(':|Line')
line = 0
f = open(file,'r')
for i in f:
if line < 400:
result = q.match(i)
answer = p.split(i)
if result or answer=='':
pass
else:
x.append(answer)
y.append(answer)
line += 1
return x,y
#x_1,y_1 = file_view(r"C:\Users\123\Desktop\you2pi.txt")
#x_2,y_2 = file_view()
x_3,y_3 = file_view(r"C:\Users\123\Desktop\you3pi.txt")
x_4,y_4 = file_view(r"C:\Users\123\Desktop\you5pi.txt")
#print(x_4[-1])
plt.figure()
#plt.plot(x_1,y_1,label='well_num = 5')
#plt.plot(x_2,y_2,label='well_num = 6')
plt.plot(x_3,y_3,label='well_num = 7')
plt.plot(x_4,y_4,label='well_num = 8')
#plt.xticks(np.arange(0,0.03,0.0001))
#plt.yticks(y_1,y_1)
plt.legend()
#x_major_locator=MultipleLocator(10)
#y_major_locator=MultipleLocator(10)
#ax=plt.gca()
#ax.xaxis.set_major_locator(x_major_locator)
#ax.yaxis.set_major_locator(y_major_locator)
plt.show()
附上代码 一个axes只能有一套横坐标import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2, 100)
plt.plot(x, x, label='linear')
plt.plot(x, x**2, label='quadratic')
plt.plot(x, x**3, label='cubic')
plt.xlabel('x label')
plt.ylabel('y label')
plt.title("Simple Plot")
plt.legend()
plt.show()
页:
[1]