在x轴上绘制错误 [英] plotting wrong on x axis
本文介绍了在x轴上绘制错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
感谢您阅读我的问题
我必须像这样绘制我的数据.当我绘制数据时
I have to plot my data like that. When I plot my data
我有这样的输出.从文件中读取数据并绘图的代码如下
I am having an output like this. Code for reading the data from the file and plotting is below
#!/usr/bin/env python3.8
import matplotlib.pyplot as plt
import numpy as np
with open('data.txt','r') as file2:
y= [line.rstrip('\n') for line in file2]
notf2=y[2:]
z=[a.rstrip(' ') for a in notf2]
x_data=[]
y_data=[]
for j in range(0, len(z)):
x_data += [z[j][:3]]
y_data += [z[j][5:]]
x__data=[]
y__data=[]
for k in range(0, len(z)):
x__data += [x_data[k]]
y__data += [y_data[k]]
rx=x__data.reverse()
ry=y__data.reverse()
#plt.plot(x__data[::-1],y__data, '.')
plt.plot(x__data,y__data, '.')
plt.show()
我不明白为什么它绘制的不同.它正在反转 x 轴但是当我试图扭转它时
I don't understand why it is plotting it different. It is reversing x axis but when I try to reverse it
plt.plot(x__data[::-1],y__data, '.')
它不是固定的,只是显示相同的东西.当我绘图
it is not fixing it , just showing the same thing. When I plot
plt.plot(x__data[::-1],y__data, '.')
plt.plot(x__data,y__data, '.')
它正在反转和显示两者.我什至不是在谈论那些写成标签的数字(黑线)
both of those it is reversing and showing . And I am not even talking about those numbers (black lines) written as if they are labels
推荐答案
您的数据是字符串.您需要将它们转换为浮点数
Your data are strings. You need to convert them to float
这篇关于在x轴上绘制错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文