Python3.6 - Plotting lat/long co-ordinates on Matplotlib [duplicate]
up vote
1
down vote
favorite
This question already has an answer here:
Difference in plotting with different matplotlib versions
1 answer
This is my first time using Matplotlib. I have a series of latitude and longitude co-ordinates in two lists, and I want to represent these in a meaningful manner. I would not like to use Basemap for several reasons.
lat = ['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951']
long = ['14.471970', '14.477780', '14.518173', '14.572245', '14.535320', '14.455894', '14.373217', '14.336096', '14.351006', '14.401137']
I am trying to represent these in a meaningful manner using Matplotlib.
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.show()
However my figure is as follows:
I am unable to set the axis in order to obtain a meaningful representation of these coordinates. How can this be done? What am I doing wrong?
I am looking for something like this:
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
plt.scatter(x, y)
plt.show()
I get the expected outcome.
I have also tried to plot on a cartesian coordinate system.
EDIT:
As per the comment below:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.axis('square')
plt.show()
python matplotlib
marked as duplicate by ImportanceOfBeingErnest
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 9 at 12:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 1 more comment
up vote
1
down vote
favorite
This question already has an answer here:
Difference in plotting with different matplotlib versions
1 answer
This is my first time using Matplotlib. I have a series of latitude and longitude co-ordinates in two lists, and I want to represent these in a meaningful manner. I would not like to use Basemap for several reasons.
lat = ['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951']
long = ['14.471970', '14.477780', '14.518173', '14.572245', '14.535320', '14.455894', '14.373217', '14.336096', '14.351006', '14.401137']
I am trying to represent these in a meaningful manner using Matplotlib.
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.show()
However my figure is as follows:
I am unable to set the axis in order to obtain a meaningful representation of these coordinates. How can this be done? What am I doing wrong?
I am looking for something like this:
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
plt.scatter(x, y)
plt.show()
I get the expected outcome.
I have also tried to plot on a cartesian coordinate system.
EDIT:
As per the comment below:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.axis('square')
plt.show()
python matplotlib
marked as duplicate by ImportanceOfBeingErnest
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 9 at 12:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Try doingplt.axis('equal')
orplt.axis('sqaure')
to get the desired effect. Source
– Rick M.
Nov 9 at 10:51
Thanks for your comment, however this does not set the axis correctly. I also tried setting specific x and y ranges, but this did not work.
– Rrz0
Nov 9 at 10:55
2
Your numbers are strings. Convert them to floats
– DavidG
Nov 9 at 10:59
1
You need to change the type of the listslat
andlong
(may be also the name for long). Try,lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
– Rick M.
Nov 9 at 10:59
@DavidG, cannot believe I overlooked this. Read data from file and missed the conversion. It worked.
– Rrz0
Nov 9 at 11:03
|
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
This question already has an answer here:
Difference in plotting with different matplotlib versions
1 answer
This is my first time using Matplotlib. I have a series of latitude and longitude co-ordinates in two lists, and I want to represent these in a meaningful manner. I would not like to use Basemap for several reasons.
lat = ['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951']
long = ['14.471970', '14.477780', '14.518173', '14.572245', '14.535320', '14.455894', '14.373217', '14.336096', '14.351006', '14.401137']
I am trying to represent these in a meaningful manner using Matplotlib.
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.show()
However my figure is as follows:
I am unable to set the axis in order to obtain a meaningful representation of these coordinates. How can this be done? What am I doing wrong?
I am looking for something like this:
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
plt.scatter(x, y)
plt.show()
I get the expected outcome.
I have also tried to plot on a cartesian coordinate system.
EDIT:
As per the comment below:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.axis('square')
plt.show()
python matplotlib
This question already has an answer here:
Difference in plotting with different matplotlib versions
1 answer
This is my first time using Matplotlib. I have a series of latitude and longitude co-ordinates in two lists, and I want to represent these in a meaningful manner. I would not like to use Basemap for several reasons.
lat = ['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951']
long = ['14.471970', '14.477780', '14.518173', '14.572245', '14.535320', '14.455894', '14.373217', '14.336096', '14.351006', '14.401137']
I am trying to represent these in a meaningful manner using Matplotlib.
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.show()
However my figure is as follows:
I am unable to set the axis in order to obtain a meaningful representation of these coordinates. How can this be done? What am I doing wrong?
I am looking for something like this:
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
plt.scatter(x, y)
plt.show()
I get the expected outcome.
I have also tried to plot on a cartesian coordinate system.
EDIT:
As per the comment below:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(lat, long)
plt.axis('square')
plt.show()
This question already has an answer here:
Difference in plotting with different matplotlib versions
1 answer
python matplotlib
python matplotlib
edited Nov 9 at 10:54
asked Nov 9 at 10:48
Rrz0
438518
438518
marked as duplicate by ImportanceOfBeingErnest
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 9 at 12:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by ImportanceOfBeingErnest
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 9 at 12:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Try doingplt.axis('equal')
orplt.axis('sqaure')
to get the desired effect. Source
– Rick M.
Nov 9 at 10:51
Thanks for your comment, however this does not set the axis correctly. I also tried setting specific x and y ranges, but this did not work.
– Rrz0
Nov 9 at 10:55
2
Your numbers are strings. Convert them to floats
– DavidG
Nov 9 at 10:59
1
You need to change the type of the listslat
andlong
(may be also the name for long). Try,lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
– Rick M.
Nov 9 at 10:59
@DavidG, cannot believe I overlooked this. Read data from file and missed the conversion. It worked.
– Rrz0
Nov 9 at 11:03
|
show 1 more comment
Try doingplt.axis('equal')
orplt.axis('sqaure')
to get the desired effect. Source
– Rick M.
Nov 9 at 10:51
Thanks for your comment, however this does not set the axis correctly. I also tried setting specific x and y ranges, but this did not work.
– Rrz0
Nov 9 at 10:55
2
Your numbers are strings. Convert them to floats
– DavidG
Nov 9 at 10:59
1
You need to change the type of the listslat
andlong
(may be also the name for long). Try,lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
– Rick M.
Nov 9 at 10:59
@DavidG, cannot believe I overlooked this. Read data from file and missed the conversion. It worked.
– Rrz0
Nov 9 at 11:03
Try doing
plt.axis('equal')
or plt.axis('sqaure')
to get the desired effect. Source– Rick M.
Nov 9 at 10:51
Try doing
plt.axis('equal')
or plt.axis('sqaure')
to get the desired effect. Source– Rick M.
Nov 9 at 10:51
Thanks for your comment, however this does not set the axis correctly. I also tried setting specific x and y ranges, but this did not work.
– Rrz0
Nov 9 at 10:55
Thanks for your comment, however this does not set the axis correctly. I also tried setting specific x and y ranges, but this did not work.
– Rrz0
Nov 9 at 10:55
2
2
Your numbers are strings. Convert them to floats
– DavidG
Nov 9 at 10:59
Your numbers are strings. Convert them to floats
– DavidG
Nov 9 at 10:59
1
1
You need to change the type of the lists
lat
and long
(may be also the name for long). Try, lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
– Rick M.
Nov 9 at 10:59
You need to change the type of the lists
lat
and long
(may be also the name for long). Try, lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
– Rick M.
Nov 9 at 10:59
@DavidG, cannot believe I overlooked this. Read data from file and missed the conversion. It worked.
– Rrz0
Nov 9 at 11:03
@DavidG, cannot believe I overlooked this. Read data from file and missed the conversion. It worked.
– Rrz0
Nov 9 at 11:03
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
As mentioned in the comment, change the type to float:
import numpy as np
import matplotlib.pyplot as plt
lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607',
'35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
long = np.array(['14.471970', '14.477780', '14.518173', '14.572245', '14.535320',
'14.455894', '14.373217', '14.336096', '14.351006', '14.401137'], dtype=float)
fig, ax = plt.subplots(figsize=(10, 6))
ax.scatter(lat, long)
# ax.axis('equal')
plt.show()
Thanks, alsoax.scatter(long, lat)
to actually represent on how points were taken from map
– Rrz0
Nov 9 at 11:06
Maybe your answer suffices for the OP's aims but (BUT) geographical coordinates should be projected...
– gboffi
Nov 9 at 11:50
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
As mentioned in the comment, change the type to float:
import numpy as np
import matplotlib.pyplot as plt
lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607',
'35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
long = np.array(['14.471970', '14.477780', '14.518173', '14.572245', '14.535320',
'14.455894', '14.373217', '14.336096', '14.351006', '14.401137'], dtype=float)
fig, ax = plt.subplots(figsize=(10, 6))
ax.scatter(lat, long)
# ax.axis('equal')
plt.show()
Thanks, alsoax.scatter(long, lat)
to actually represent on how points were taken from map
– Rrz0
Nov 9 at 11:06
Maybe your answer suffices for the OP's aims but (BUT) geographical coordinates should be projected...
– gboffi
Nov 9 at 11:50
add a comment |
up vote
1
down vote
accepted
As mentioned in the comment, change the type to float:
import numpy as np
import matplotlib.pyplot as plt
lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607',
'35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
long = np.array(['14.471970', '14.477780', '14.518173', '14.572245', '14.535320',
'14.455894', '14.373217', '14.336096', '14.351006', '14.401137'], dtype=float)
fig, ax = plt.subplots(figsize=(10, 6))
ax.scatter(lat, long)
# ax.axis('equal')
plt.show()
Thanks, alsoax.scatter(long, lat)
to actually represent on how points were taken from map
– Rrz0
Nov 9 at 11:06
Maybe your answer suffices for the OP's aims but (BUT) geographical coordinates should be projected...
– gboffi
Nov 9 at 11:50
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
As mentioned in the comment, change the type to float:
import numpy as np
import matplotlib.pyplot as plt
lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607',
'35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
long = np.array(['14.471970', '14.477780', '14.518173', '14.572245', '14.535320',
'14.455894', '14.373217', '14.336096', '14.351006', '14.401137'], dtype=float)
fig, ax = plt.subplots(figsize=(10, 6))
ax.scatter(lat, long)
# ax.axis('equal')
plt.show()
As mentioned in the comment, change the type to float:
import numpy as np
import matplotlib.pyplot as plt
lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607',
'35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
long = np.array(['14.471970', '14.477780', '14.518173', '14.572245', '14.535320',
'14.455894', '14.373217', '14.336096', '14.351006', '14.401137'], dtype=float)
fig, ax = plt.subplots(figsize=(10, 6))
ax.scatter(lat, long)
# ax.axis('equal')
plt.show()
answered Nov 9 at 11:01
Rick M.
1,8141922
1,8141922
Thanks, alsoax.scatter(long, lat)
to actually represent on how points were taken from map
– Rrz0
Nov 9 at 11:06
Maybe your answer suffices for the OP's aims but (BUT) geographical coordinates should be projected...
– gboffi
Nov 9 at 11:50
add a comment |
Thanks, alsoax.scatter(long, lat)
to actually represent on how points were taken from map
– Rrz0
Nov 9 at 11:06
Maybe your answer suffices for the OP's aims but (BUT) geographical coordinates should be projected...
– gboffi
Nov 9 at 11:50
Thanks, also
ax.scatter(long, lat)
to actually represent on how points were taken from map– Rrz0
Nov 9 at 11:06
Thanks, also
ax.scatter(long, lat)
to actually represent on how points were taken from map– Rrz0
Nov 9 at 11:06
Maybe your answer suffices for the OP's aims but (BUT) geographical coordinates should be projected...
– gboffi
Nov 9 at 11:50
Maybe your answer suffices for the OP's aims but (BUT) geographical coordinates should be projected...
– gboffi
Nov 9 at 11:50
add a comment |
Try doing
plt.axis('equal')
orplt.axis('sqaure')
to get the desired effect. Source– Rick M.
Nov 9 at 10:51
Thanks for your comment, however this does not set the axis correctly. I also tried setting specific x and y ranges, but this did not work.
– Rrz0
Nov 9 at 10:55
2
Your numbers are strings. Convert them to floats
– DavidG
Nov 9 at 10:59
1
You need to change the type of the lists
lat
andlong
(may be also the name for long). Try,lat = np.array(['35.905333', '35.896389', '35.901281', '35.860491', '35.807607', '35.832267', '35.882414', '35.983794', '35.974463', '35.930951'], dtype=float)
– Rick M.
Nov 9 at 10:59
@DavidG, cannot believe I overlooked this. Read data from file and missed the conversion. It worked.
– Rrz0
Nov 9 at 11:03