Blake
Blake

Reputation: 1

Matplotlib Graph For Geopandas Geometry is Too Small

The plot is completely squished and unreadable. I can't seem to figure out how to expand the graph.

Tried setting the axis x and y limits, but the scales are still shrunk down. I think it's an issue with the fig variable. Any ideas?

from shapely.geometry import shape
import matplotlib.pyplot as plt
import geopandas as gp

point = {
    "geometry": {
        "coordinates": [
          -91.76072108494787,
          34.77920107121595
        ],
        "type": "Point"
      }
}

line = {
        "geometry": {
            "coordinates": [
          [
            -91.8055414669353,
            34.77957005084145
          ],
          [
            -91.80550349155497,
            34.779569646508634
          ],
          [
            -91.80548225807662,
            34.77956941999371
          ],
          [
            -91.8049339327154,
            34.779562463697765
          ],
          [
            -91.80405717879474,
            34.77955448623926
          ],
          [
            -91.80402976939877,
            34.77955423685145
          ],
          [
            -91.80387683211995,
            34.779552845296884
          ],
          [
            -91.80327339960765,
            34.77954667848177
          ],
          [
            -91.80270712680536,
            34.77954056479025
          ],
          [
            -91.80263101973786,
            34.779539742843276
          ],
          [
            -91.8025065195277,
            34.77953839850987
          ],
          [
            -91.80196402423266,
            34.77953243607369
          ],
          [
            -91.80162845765996,
            34.77952417749752
          ],
          [
            -91.80134907711502,
            34.77951728170013
          ],
          [
            -91.80131165689356,
            34.77951635866968
          ],
          [
            -91.80103957785525,
            34.77950964290321
          ],
          [
            -91.80060233995869,
            34.77950483591334
          ],
          [
            -91.79975537237621,
            34.77949663783681
          ],
          [
            -91.79964709035018,
            34.77949550526116
          ],
          [
            -91.79813984037261,
            34.77947905081655
          ]
        ],
        "type": "LineString"
      }
}

l = shape(line["geometry"])
p = shape(point["geometry"])

p_geo = gp.GeoSeries(p)
l_geo = gp.GeoSeries(l)

fig, ax = plt.subplots()
ax.set_aspect('equal')


l_geo.plot(ax=ax, color='black', edgecolor='black')
p_geo.plot(ax=ax, marker='o', color='red', markersize=5)

plt.show()

enter image description here

Upvotes: 0

Views: 444

Answers (1)

Abhilshit
Abhilshit

Reputation: 196

Based on your data I tried setting a y_lim of ax.set_ylim(34.778,34.8) and obtained the following results

enter image description here

Since, your Y values for the linestring has very little variation, I would suggest you identify the min and max Y values using the following method and use them to set y_lim

p_geo = gp.GeoSeries(p)
l_geo = gp.GeoSeries(l)
min_y = l_geo.geometry.bounds['miny']
max_y = l_geo.geometry.bounds['maxy']

print(min_y)
print(max_y)

Upvotes: 2

Related Questions