鱼C论坛

 找回密码
 立即注册
查看: 1141|回复: 1

python绘制折线图

[复制链接]
发表于 2021-9-23 15:19:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
怎么把两个横坐标不一样的数据绘制在一起
360截图20210923151000891.jpg
360截图20210923151354376.jpg
它们数据都不会并到一起,横坐标0.18407后面接着跟4.86334e-14了
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[1]=='':
                pass
            else:
                x.append(answer[0])
                y.append(answer[1])
                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()
附上代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-23 15:41:51 | 显示全部楼层
一个axes只能有一套横坐标
  1. import matplotlib.pyplot as plt
  2. import numpy as np

  3. x = np.linspace(0, 2, 100)
  4. plt.plot(x, x, label='linear')
  5. plt.plot(x, x**2, label='quadratic')
  6. plt.plot(x, x**3, label='cubic')
  7. plt.xlabel('x label')
  8. plt.ylabel('y label')
  9. plt.title("Simple Plot")
  10. plt.legend()
  11. plt.show()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-19 10:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表