Plotting from a data file

Hi,

That doesn’t work. Just having my own msft.csv file in my directory doesn't change anything as it is still pointing to some other msft.csv someplace on my computron. (what and where is this file?)

I also have never opened a file this way. I had prevously just used something like:

for l in open(filename).readlines():
   l = l.strip().split()
   data.append([float(l[0]), float(l[1]), float(l[2]), int(l[3])])

values = [1,2,3,4]

···

-

I think ithis is just some example file that gets installed some place so that the examples work?

What does asfileobj=False do?

Goodness the whole world of Python has radically changed in the short time I have been out of the game.

On Aug 15, 2015, at 1:50 AM, Christian Alis <ianalis@...287...> wrote:

The sample code reads data from msft.csv. If you enter your data into
a text editor and save it as msft.csv in python's current working
directory, then the following minimal code (pruned from plotfile_demo)
should work:

from pylab import plotfile, show, gca
import matplotlib.cbook as cbook

fname = cbook.get_sample_data('msft.csv', asfileobj=False)

#test 5; single subplot
plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False)

show()

Maybe using “genfromtxt" is simpler as a way to get going, see below for a fragment of script? It should be able to read a CSV file since it’s just a comma delimited text file. You might need to look up how to set the delimiter character.
regards
Tony Rollet

···

#!/usr/bin/env python
"""
simple line/scatter plot.
"""
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
from numpy import *
import scipy.interpolate

isosphere = genfromtxt("KAM_test_5Oct14strs_strn.txt", names=True )

On Aug 14, 2015, at 12:05 PM, Kevin Parks <kp8@...2904...> wrote:

Hi,

That doesn’t work. Just having my own msft.csv file in my directory doesn't change anything as it is still pointing to some other msft.csv someplace on my computron. (what and where is this file?)

I also have never opened a file this way. I had prevously just used something like:

for l in open(filename).readlines():
  l = l.strip().split()
  data.append([float(l[0]), float(l[1]), float(l[2]), int(l[3])])

values = [1,2,3,4]

-

I think ithis is just some example file that gets installed some place so that the examples work?

What does asfileobj=False do?

Goodness the whole world of Python has radically changed in the short time I have been out of the game.

On Aug 15, 2015, at 1:50 AM, Christian Alis <ianalis@...287...> wrote:

The sample code reads data from msft.csv. If you enter your data into
a text editor and save it as msft.csv in python's current working
directory, then the following minimal code (pruned from plotfile_demo)
should work:

from pylab import plotfile, show, gca
import matplotlib.cbook as cbook

fname = cbook.get_sample_data('msft.csv', asfileobj=False)

#test 5; single subplot
plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False)

show()

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

All “cbook.get_sample_data(…, asfileobj=False)” does is returns the full filename path to a given file stored in our package for demonstration purposes. You can ignore that entirely. Just say “fname = ‘foobar.csv’” and have your own csv file called “foobar.csv” sitting in your current working directory. “plotfile()” works by reading in a CSV file and plotting the columns given. So, the CSV file will need in its first line those column headers. The first one given will be for the x-axis, while the rest are for the individual lines.

Does that help?

Ben Root

···

On Fri, Aug 14, 2015 at 1:05 PM, Kevin Parks <kp8@…2904…> wrote:

Hi,

That doesn’t work. Just having my own msft.csv file in my directory doesn’t change anything as it is still pointing to some other msft.csv someplace on my computron. (what and where is this file?)

I also have never opened a file this way. I had prevously just used something like:

for l in open(filename).readlines():

l = l.strip().split()

data.append([float(l[0]), float(l[1]), float(l[2]), int(l[3])])

values = [1,2,3,4]

I think ithis is just some example file that gets installed some place so that the examples work?

What does asfileobj=False do?

Goodness the whole world of Python has radically changed in the short time I have been out of the game.

On Aug 15, 2015, at 1:50 AM, Christian Alis <ianalis@…287…> wrote:

The sample code reads data from msft.csv. If you enter your data into

a text editor and save it as msft.csv in python’s current working

directory, then the following minimal code (pruned from plotfile_demo)

should work:

from pylab import plotfile, show, gca

import matplotlib.cbook as cbook

fname = cbook.get_sample_data(‘msft.csv’, asfileobj=False)

#test 5; single subplot

plotfile(fname, (‘date’, ‘open’, ‘high’, ‘low’, ‘close’), subplots=False)

show()



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

According to http://matplotlib.org/1.4.3/api/cbook_api.html#matplotlib.cbook.get_sample_data,
msft.csv should be located at the mpl-data/sample_data directory.

In that case, save the following as sample.csv on the current directory:

event_start_time, event_duration, frequency_value, voice
0.0, 2.5, 60, 1
2.0, 1.5, 62, 4
4.0, 5.0, 64, 2
6.0, 3.5, 65, 3
8.0, 1.5, 67, 1
10.0, 2.0, 69, 4
12.0, 5.5, 71, 3
14.0, 3.0, 70, 2
16.0, 2.0, 72, 1
18.0, 1.0, 74, 4
20.0, 0.5, 75, 3
22.0, 1.5, 77, 2
24.0, 0.5, 79, 1

Then run the following code:

from pylab import plotfile, show, gca

#test 5; single subplot
plotfile('sample.csv', ('event_start_time', 'event_duration',
'frequency_value', 'voice'), subplots=False)

show()

Regards,

Christian

···

On Fri, Aug 14, 2015 at 6:05 PM, Kevin Parks <kp8@...2904...> wrote:

Hi,

That doesn’t work. Just having my own msft.csv file in my directory doesn't change anything as it is still pointing to some other msft.csv someplace on my computron. (what and where is this file?)

I also have never opened a file this way. I had prevously just used something like:

for l in open(filename).readlines():
   l = l.strip().split()
   data.append([float(l[0]), float(l[1]), float(l[2]), int(l[3])])

values = [1,2,3,4]

-

I think ithis is just some example file that gets installed some place so that the examples work?

What does asfileobj=False do?

Goodness the whole world of Python has radically changed in the short time I have been out of the game.

On Aug 15, 2015, at 1:50 AM, Christian Alis <ianalis@...287...> wrote:

The sample code reads data from msft.csv. If you enter your data into
a text editor and save it as msft.csv in python's current working
directory, then the following minimal code (pruned from plotfile_demo)
should work:

from pylab import plotfile, show, gca
import matplotlib.cbook as cbook

fname = cbook.get_sample_data('msft.csv', asfileobj=False)

#test 5; single subplot
plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False)

show()

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

That does help. But then that means I need to reformat my data somehow? I want it so that each “voice” is plotted separately as a unique color and my legend would be

Voice 1 -----
Voice 2 -----
Voice 3 -----
Voice 4 -----

Just as if I had the temperature for four different days plotted.

confused

···

On Aug 15, 2015, at 2:14 AM, Benjamin Root <ben.root@...1304...> wrote:

All "cbook.get_sample_data(..., asfileobj=False)" does is returns the full filename path to a given file stored in our package for demonstration purposes. You can ignore that entirely. Just say "fname = 'foobar.csv'" and have your own csv file called "foobar.csv" sitting in your current working directory. "plotfile()" works by reading in a CSV file and plotting the columns given. So, the CSV file will need in its first line those column headers. The first one given will be for the x-axis, while the rest are for the individual lines.

Does that help?
Ben Root

If you are trying to read a CSV file, I strongly suspect using pandas for ingesting them.

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html

Also, please use the new mailing list at matplotlib-users@…48…

Tom

···

On Fri, Aug 14, 2015 at 1:39 PM Anthony Rollett <rollett@…1648…> wrote:

Maybe using “genfromtxt" is simpler as a way to get going, see below for a fragment of script? It should be able to read a CSV file since it’s just a comma delimited text file. You might need to look up how to set the delimiter character.

regards

Tony Rollet

#!/usr/bin/env python

“”"

simple line/scatter plot.

“”"

import matplotlib

import numpy as np

import matplotlib.cm as cm

import matplotlib.mlab as mlab

import matplotlib.pyplot as plt

from numpy import *

import scipy.interpolate

isosphere = genfromtxt(“KAM_test_5Oct14strs_strn.txt”, names=True )

On Aug 14, 2015, at 12:05 PM, Kevin Parks <kp8@…2904…> wrote:

Hi,

That doesn’t work. Just having my own msft.csv file in my directory doesn’t change anything as it is still pointing to some other msft.csv someplace on my computron. (what and where is this file?)

I also have never opened a file this way. I had prevously just used something like:

for l in open(filename).readlines():

l = l.strip().split()

data.append([float(l[0]), float(l[1]), float(l[2]), int(l[3])])

values = [1,2,3,4]

I think ithis is just some example file that gets installed some place so that the examples work?

What does asfileobj=False do?

Goodness the whole world of Python has radically changed in the short time I have been out of the game.

On Aug 15, 2015, at 1:50 AM, Christian Alis <ianalis@…287…> wrote:

The sample code reads data from msft.csv. If you enter your data into

a text editor and save it as msft.csv in python’s current working

directory, then the following minimal code (pruned from plotfile_demo)

should work:

from pylab import plotfile, show, gca

import matplotlib.cbook as cbook

fname = cbook.get_sample_data(‘msft.csv’, asfileobj=False)

#test 5; single subplot

plotfile(fname, (‘date’, ‘open’, ‘high’, ‘low’, ‘close’), subplots=False)

show()



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users