[Tutor] Created map after opening file

Alan Gauld alan.gauld at yahoo.co.uk
Thu Oct 20 05:54:20 EDT 2016


On 20/10/16 05:31, Betty Cruz wrote:
> Hello, I'm new to python. 

Hello, welcome.

> ...I'm trying to create a map after reading a file.

What kind of "map" - that's a very generic term.
Do you mean a geographic map using GIS data?
If so is it some kind of image output that you want?

Or is it a map as in Java? In other words a
dictionary using Python-speak?

Or is it a more general mapping of one value to another?

> I have downloaded python 3, anaconda, and pycharm.
For completeness which OS are you running?

These imply you are into math/science so maybe
its a more specific kind of map?

But we really can't guess, you will need to tell us.

You should not assume that everyone on the list
will understand your questions if you use technical
terms. You may get lucky and find a kindred soul
but there's no guarantee so you really need to
explain your problem in terms that most list
readers can understand. (That, in turn, may
even help you to understand it better yourself! :-)

> I have written some code, but I'm having trouble reading the file...How do
> I read the file so that it reads the data and makes the map? 

Unless this a ScyPy/NumPy specific kind of map you
are probably going to have to split those activities
into two.

> My data is only in rows...the first row are the x's 
> and the second row are the y's.

Can you send a sample, say 4-6 rows?

> Any help would be appreciated. I have tried to run the program. but I just
> get an error, saying that the directory for the file is not found.

Always send the complete error text. The error messages are
full of useful data but that doesn't help us if we can't see it.
If it's complaining about the directory though that does
suggest that it's a path issue - did you try specifying
the full path to the file?

> import numpy as np
> import matplotlib.pyplot as plt
> 
> data= np.loadtxt('mat.dat')

What does 'data' look like at this point?
Have you tried printing it?

print(data)

That's often the first step in debugging
a problem. Most Python types will have some
kind of readable representation from a print
(although not all...)
Check that what you got is what you expected.

> #data = np.genfromtxt('map.dat')
> # plot the first column as x, and second column as y
> #pl.plot(data[:,0], data[:,1], ’ro’)
> #pl.xlabel(’x’)
> #pl.ylabel(’y’)
> #pl.xlim(0.0, 90.0)
> #pl.ylim(10.0, 80.0)
> #pl.show()

This looks like a straight plot of the data, is that
what you meant by a "map"? If so then there is a good
tutorial on using matplotlib on the SciPy site which
should show you what you need.

http://matplotlib.org/users/beginner.html

The only difficulty may be in reading the data, but
we can't help with that until we can see what it
looks like.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list