首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅在左侧绘制,并显示黑条而不是x轴标签

仅在左侧绘制,并显示黑条而不是x轴标签
EN

Stack Overflow用户
提问于 2020-07-28 20:21:27
回答 1查看 35关注 0票数 1

我有一个通过读取CSV文件生成的图,出于某种原因,当它被绘制时,它做了一件非常奇怪的事情,把图一直压到了图的左边,并用黑条代替了xlabels。我已经包含了一个绘图的图像,以向您展示我的意思,以及用于绘制它的代码。任何帮助都将不胜感激。

代码语言:javascript
复制
def plot_exp(self, filename):  # Plots what is selected using expButton, using the filename from exp_clicked
    self.axes.set_xlim(200, 3000)  # Sets the axes limits
    self.axes.set_xlabel('Energy (eV)')  # Sets the x label
    self.axes.set_ylabel('Intensity (a.u.)')  # Sets the y label
    df = pd.read_csv(filename, sep='\t')  # Reads the .csv file with appropriate separator
    df_exp = df[df.columns[::2]]  # Skips every other column in the .csv file as each is exported twice
    df_exp = df_exp.drop(df_exp.columns[1], axis=1)  # Drops the first column which is irrelevant
    df_exp = df_exp.drop(df_exp.columns[2:7], axis=1)  # Drops columns 2-7 which are also irrelevant
    df_exp.columns = ['Energy', 'Intensity']  # Renames columns
    df_exp = df_exp[df_exp['Intensity'] > 0]  # Only reads data points which are greater than 0
    df_exp['Energy'] = df_exp['Energy'].str.replace(',', '')  # Replaces the comma separator with nothing
    df_exp.to_csv('/Volumes/GoogleDrive/My Drive/MAT 395/Project/Exported Data/Experimental_Plot.csv', index=False)
    # Exports plotted data to .csv
    self.axes.plot(df_exp['Energy'], df_exp['Intensity'])  # Plots the experimental data file
    self.draw()  # Draws the plot onto the canvas

EN

回答 1

Stack Overflow用户

发布于 2020-07-28 20:59:07

df_exp['Energy'].dtypenp.object,所以不能解释为float。解决方案是将其类型转换为float

代码语言:javascript
复制
df_exp['Energy'] = df_exp['Energy'].astype(np.float, copy=False)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63134029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档