<jupyter_start><jupyter_text>Creating two collections of points- N evenly spaced points around the north pole at 80 deg. latitude - A straight line from Nijmegen (NL) to Berlin (DE)(in lat/lon coordinates)<jupyter_code>N = 50

longs = np.linspace(-180,180,num=N,endpoint=False)
lats = np.ones(N)*80.0

y = lats
x = longs


polarCircle = pd.DataFrame({"x":x, "y":y})
N = 50

cityA = np.array([5.84280, 51.8449])
cityB = np.array([13.4050, 52.5200])

t = np.linspace(0,1,num=N)[:,np.newaxis]

path = (1-t)*cityA + t*cityB

someLine = pd.DataFrame(path,columns=["x","y"])<jupyter_output><empty_output><jupyter_text>Two plotting methodsBoth methods create a `Basemap` using the `srid` defined by the dataset.`plotA` plots raw point coordinates, `plotB` converts them first using the `Basemap`.<jupyter_code>def plotA(points, srid, ax, bounds):
    x1, x2, y1, y2 = bounds
    databmap = Basemap(epsg=srid, ax=ax, llcrnrlat=y1, urcrnrlat=y2, llcrnrlon=x1, urcrnrlon=x2)
    databmap.drawcountries()
    databmap.drawcoastlines()
    # --------------
    # Key difference:
    x,y = points["x"].values, points["y"].values
    # --------------
    bus_collection = ax.scatter(x,y, c='b', edgecolor='face')


def plotB(points, srid, ax, bounds):
    x1, x2, y1, y2 = bounds
    databmap = Basemap(epsg=srid, ax=ax, llcrnrlat=y1, urcrnrlat=y2, llcrnrlon=x1, urcrnrlon=x2)
    databmap.drawcountries()
    databmap.drawcoastlines()
    # --------------
    # Key difference:
    x,y = databmap(points["x"].values, points["y"].values, inverse=False)
    print(x,y)
    # --------------
    bus_collection = ax.scatter(x,y, c='b', edgecolor='face')<jupyter_output><empty_output><jupyter_text>Lat/lon dataset<jupyter_code>fig, axes = plt.subplots(2,2)
fig.set_size_inches(15,8)


geBounds = [0,20,50,60]
wwBounds = [-170,170,-85,85]


plotA(someLine, None, axes[0,0], geBounds)
plotA(polarCircle, None, axes[0,1], wwBounds)
plotB(someLine, None, axes[1,0], geBounds)
plotB(polarCircle, None, axes[1,1], wwBounds)


axes[0,0].set_title("plotA")
axes[0,1].set_title("plotA")
axes[1,0].set_title("plotB")
axes[1,1].set_title("plotB")<jupyter_output><empty_output><jupyter_text>Both plotting methods produce the same result (since the dataset is in lat/lon coordinates)  Transformed dataset<jupyter_code># The mercator projection: http://spatialreference.org/ref/epsg/wgs-84-world-mercator/
mercSRID = "3395"

conversionbmap = Basemap(epsg=mercSRID)

def convert(df,bmap):
    x,y = bmap(df["x"].values,df["y"].values)
    return pd.DataFrame({"x":x,"y":y})

someLineMerc = convert(someLine, conversionbmap)
polarCircleMerc = convert(polarCircle, conversionbmap)

print(conversionbmap(someLineMerc["x"].values,someLineMerc["y"].values, inverse=True))
print(someLineMerc["x"].values,someLineMerc["y"].values)
print(someLine["x"].values,someLine["y"].values)


geBounds = [0,20,50,60]
plotB(someLine, mercSRID, axes[1,0], geBounds)
fig, axes = plt.subplots(2,2)
fig.set_size_inches(15,8)


geBounds = [0,20,50,60]
wwBounds = [-170,170,-85,85]



plotA(someLineMerc, mercSRID, axes[0,0], geBounds)
plotA(polarCircleMerc, mercSRID, axes[0,1], wwBounds)
plotB(someLine, mercSRID, axes[1,0], geBounds)
plotB(polarCircleMerc, mercSRID, axes[1,1], wwBounds)



axes[0,0].set_title("plotA")
axes[0,1].set_title("plotA")
axes[1,0].set_title("plotB")
axes[1,1].set_title("plotB")
x1, x2, y1, y2 = [0,20,50,60]

bmapA = Basemap(projection="merc")
bmapB = Basemap(projection="merc", llcrnrlat=-89.99, urcrnrlat=89.99, llcrnrlon=-180, urcrnrlon=180)
bmapC = Basemap(projection="merc", llcrnrlat=y1, urcrnrlat=y2, llcrnrlon=x1, urcrnrlon=x2)


# Transform the coordinate (lon: 12, lat: 52):
print(bmapA([12],[52]))
print(bmapB([12],[52]))
print(bmapC([12],[52]))
bmapA<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18587360594795538, 'fraction_numerical': 0.05151354221986192, 'mean_word_length': 5.702846975088968, 'pattern_counts': {'":': 4, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '217563', 'license': 'MIT', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1560, 'n_words': 267, 'path': 'notebooks/testing/Matplotlib basemap projection.ipynb', 'repo_name': 'fons-/grid-failures', 'size': '3766'}