Python Forum
There are problems with my data visualization function.
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
There are problems with my data visualization function.
#2
In matlab each time you plot it reuses the last axes, removing what was there. If you want to keep the previous plot you need to use the command "hold on" to avoid deleting the axes (and "hold off" when you are done) or use low level commands like "line" to plot.
The matplotlib original design follows this mode, so you need to use "plt.hold(True)" to keep the previous things in the axis. But this behaviour is deprecated since version 2 and now the default is to do not delete the content of the axes.
So either you have a really old version of matplotlib installed or you have a configuration file with a "axes.hold: False"

I do not have your input data to check if this code works, but I think there are 2 ways to fix this:
  • The "Please don't do this, is deprecated" way:
    plt.imshow(mpimg.imread('map.png'), extent=(149.105, 149.130, -35.29, -35.27))
    plt.hold(True)
    plt.scatter(latitude, longtitude)
    plt.hold(False)
    plt.show()
  • The "keep control of your axes" way:
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    img = mpimg.imread('map.png')
    xlim = (149.105, 149.130)
    ylim = (-35.29, -35.27)
    # Show the background
    ax.imshow(img, extent=xlim + ylim)
    # Plot the lat-lon
    ax.scatter(latitude, longtitude)
    # Keep the axes in the right ranges
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)
    plt.show()

Just to add a small thing, you can clean up your loop avoiding to iterate "by index" that is quite inefficient in python (and I suspect you are missing the initial point):
latitude = []
longtitude = []
for point in altas_data:
    latitude.append(float(point[1]))
    longitude.append(float(point[2]))
Or depending of the format of altas_data you can even do it as:
import numpy as np
data = np.array(altas_data, dtype=float)
latitude = data[:, 1]
longitude = data[:, 2]
Take a look to cartopy to plot information in a map... the initial steps are a little bit difficult, but then you can do really amazing things.
Reply


Messages In This Thread
RE: There are problems with my data visualization function. - by killerrex - May-20-2018, 10:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  passing a value to function problems Ponamis 2 2,072 Nov-14-2018, 05:05 PM
Last Post: Larz60+
  Problems with isdigit function Omegax77 2 3,068 Jun-30-2018, 06:48 PM
Last Post: woooee

Forum Jump:

User Panel Messages

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