Created
January 15, 2021 03:04
-
-
Save thezakman/138f3f891af061643af5a57d67bdb53a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Longitude and latitude coordinates of the left bottom: (113.538285, 22.120002) | |
# Longitude and latitude coordinates of the right bottom: (113.548080, 22.120002) | |
# Longitude and latitude coordinates of the left top: (113.538285, 22.137862) | |
# import packages | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.image as mpimg | |
#Add Circles with labels | |
def AddLabels(circle,x,y,RGB,value): | |
fig, ax = plt.subplots() | |
ax = fig.add_subplot(111) | |
circle = plt.Circle((x, y), radius=35, color=RGB) | |
label = ax.annotate(value, xy=(x, y), fontsize=15, ha="center") | |
ax.add_patch(circle) | |
ax.axis('off') | |
ax.set_aspect('equal') | |
ax.autoscale_view() | |
AddLabels("c1",970,820,"#ffab00","2054") | |
# setting the Longitude and latitude coordinates | |
longitude_begin = 113.538285 | |
longitude_end = 113.548080 | |
latitude_begin = 22.120002 | |
latitude_end = 22.137862 | |
left_x = 0. | |
right_x = 1830. | |
top_y = 0. | |
bottom_y = 3606. | |
x_per_longitude = right_x / (longitude_end - longitude_begin) | |
y_per_latitude = bottom_y / (latitude_end - latitude_begin) | |
def convert_coordinates(longitude, latitude): | |
x = (longitude - longitude_begin) * x_per_longitude | |
y = bottom_y - ((latitude - latitude_begin) * y_per_latitude) | |
return x, y | |
def plot_um_map(): | |
# read and plot um's map | |
img = mpimg.imread('ummap.jpeg') | |
plt.imshow(img) | |
ylen, xlen, _ = img.shape | |
# change x ticks | |
x_ticks = np.linspace(0, xlen, 3) | |
x_labels = np.linspace(longitude_begin, longitude_end, 3) | |
# change y ticks | |
y_ticks = np.linspace(0, ylen, 5) | |
y_labels = np.linspace(latitude_end, latitude_begin, 5) | |
def scatter_on_ummap(longitudes, latitudes, connectivity=None, **kwargs): | |
xs, ys = convert_coordinates(longitudes, latitudes) | |
plt.scatter(xs, ys, c=connectivity, cmap="autumn",**kwargs,) | |
def arrow_on_ummap(x, y): | |
x, y = convert_coordinates(x, y) | |
plt.quiver(x[:-1], y[:-1], x[1:]-x[:-1], y[1:]-y[:-1], scale_units='xy', angles='xy', scale=1) | |
if __name__ == "__main__": | |
plot_um_map() | |
scatter_on_ummap(113.546534, 22.132590) | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment