Python Forum
Simple plotting from txt file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple plotting from txt file
#1
I have a very simple code to plot. The data file consists of seven columns with values (not integers), and I wish to plot their division. This is the code:

import pandas as pd
data = pd.read_csv('Co_foil_2.data',sep='\s+',header=None)
data = pd.DataFrame(data)

import matplotlib.pyplot as plt
y = data[0]
a = (data[1]/data[2])
b = (data[2]/data[2])
c = (data[3]/data[2])
d = (data[4]/data[2])
e = (data[5]/data[2])
f = (data[6]/data[2])

plt.plot(a, y,'r--')
plt.plot(b, y,'b--')
plt.plot(c, y,'g--')
plt.plot(d, y,'y--')
plt.plot(e, y,'m--')
plt.plot(f, y,'k--')
plt.legend()
plt.show()
However, this returns an error:

TypeError: unsupported operand type(s) for /: 'str' and 'str'
From what I understand, the columns can't be divided for some reason; am I simply using a wrong command, or is there something more prominently wrong in the code?
Reply


Messages In This Thread
Simple plotting from txt file - by Laplace12 - Aug-22-2020, 01:34 PM
RE: Simple plotting from txt file - by deanhystad - Aug-22-2020, 03:50 PM
RE: Simple plotting from txt file - by Laplace12 - Aug-23-2020, 09:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Plotting simple graph (AttributeError) Laplace12 0 1,377 Jul-28-2021, 10:58 AM
Last Post: Laplace12
  [Solved] Plotting data from txt file Laplace12 1 1,822 Jul-06-2021, 07:14 AM
Last Post: Laplace12
  Plotting sum of data files using simple code Laplace12 3 3,062 Jun-16-2021, 02:06 PM
Last Post: BashBedlam
  Plotting “simple” diagram with gridlines at specified intervals schniefen 1 2,425 Dec-03-2020, 05:54 PM
Last Post: schniefen
  Using a .bat file to execute simple anaconda commands in Windows 10 gacg1 0 4,694 Nov-30-2020, 03:24 PM
Last Post: gacg1
  Simple Read File Issue blackjesus24 4 2,777 Feb-09-2020, 12:07 AM
Last Post: blackjesus24
  Looking for simple help - text file stripping DerekK 1 2,138 Mar-08-2019, 10:06 AM
Last Post: Larz60+
  Plotting distribution of a variable on the map with a shape file fyec 0 2,041 Jun-22-2018, 09:43 PM
Last Post: fyec

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020