gboeing / osmnx

OSMnx is a Python package to easily download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap.
https://osmnx.readthedocs.io
MIT License
4.74k stars 814 forks source link

'PolarAxesSubplot' object is not iterable on running 17-street-network-orientations.ipynb #181

Closed vr00n closed 5 years ago

vr00n commented 5 years ago

The issue tracker is for reporting bugs and feature requests. For general questions, see the contributing guidelines in CONTRIBUTING.md.

If you're having trouble with OSMnx, first search the previously opened issues to see if the problem has already been noted. If not, fill in the template below. You can delete any sections that don't apply.

Problem description (what did you do, what did you expect to happen, and what actually happened)

When trying to run 17-street-network-orientations.ipynb, I get an error 'PolarAxesSubplot' object is not iterable

What operating system, architecture, Python version, and OSMnx version are you using?

MAC OSX High Sierra v.10.13.15 Python Python 2.7.11 osmnx (0.8.1)

Complete list of your environment's packages and their versions (for example, run conda list or pip list then paste the output below)

# Paste the output of your Python packages and their versions here, between these two "details" tags abstract-rendering (0.5.1) agate (1.6.0) agate-dbf (0.2.0) agate-excel (0.2.1) agate-sql (0.5.2) alabaster (0.7.3) alembic (0.9.2) amqp (1.4.9) anaconda-client (1.2.2) anyjson (0.3.3) appnope (0.1.0) appscript (1.0.1) argcomplete (0.8.9) arrow (0.8.0) astropy (1.0.3) Babel (2.4.0) backports.functools-lru-cache (1.5) backports.shutil-get-terminal-size (1.0.0) backports.ssl-match-hostname (3.4.0.2) bcolz (0.9.0) BeautifulSoup (3.2.1) beautifulsoup4 (4.5.3) billiard (3.3.0.23) binstar (0.11.0) bitarray (0.8.1) blaze (0.8.0) bleach (2.0.0) blz (0.6.2) bokeh (0.9.0) boto (2.42.0) boto3 (1.4.4) botocore (1.5.53) Bottleneck (1.0.0) branca (0.2.0) cchardet (1.1.1) cdecimal (2.3) celery (3.1.23) certifi (2018.4.16) cffi (1.9.1) chardet (3.0.4) click (6.7) click-plugins (1.0.3) cligj (0.4.0) clyent (0.3.4) colorama (0.3.2) colorlog (2.4.0) conda (4.1.3) conda-build (1.14.1) conda-env (2.5.0a0) configobj (5.0.6) configparser (3.5.0) cryptography (1.7.2) csvkit (1.0.2) cycler (0.10.0) Cython (0.22.1) cytoolz (0.7.3) daff (1.3.24) datashape (0.4.5) dbf (0.94.3) dbfread (2.0.7) decorator (4.3.0) descartes (1.1.0) docutils (0.12) ecdsa (0.13) entrypoints (0.2.3) enum34 (1.1.6) et-xmlfile (1.0.1) ExifRead (1.4.1) fastcache (1.0.2) Fiona (1.7.12) Flask (0.10.1) Flask-AppBuilder (1.8.1) Flask-Babel (0.11.2) Flask-Cache (0.13.1) Flask-Login (0.2.11) Flask-Migrate (2.0.3) Flask-OpenID (1.2.5) Flask-Script (2.0.5) Flask-SQLAlchemy (2.0) Flask-Testing (0.6.2) Flask-WTF (0.14.2) folium (0.5.0) ftputil (3.3.1) funcsigs (1.0.2) functools32 (3.2.3.post2) future (0.16.0) futures (3.1.1) gcalcli (3.3.2) geopandas (0.3.0) geopy (1.11.0) gevent (1.0.1) gevent-websocket (0.9.3) glueviz (0.5.1) google-api-python-client (1.5.1) googlemaps (2.4.6) gpxpy (0.9.8) greenlet (0.4.7) grin (1.2.1) gunicorn (19.7.1) h5py (2.5.0) html5lib (0.999999999) httplib2 (0.9.2) humanize (0.5.1) idna (2.7) ijson (2.3) IndicoIo (1.1.1) ipaddress (1.0.17) ipykernel (4.6.1) ipython (5.4.1) ipython-genutils (0.2.0) ipywidgets (6.0.0) isodate (0.5.4) itsdangerous (0.24) JayDeBeApi (0.2.0) jdcal (1.3) jedi (0.8.1) Jinja2 (2.7.3) jmespath (0.9.2) JPype1 (0.6.1) jsonpath-rw (1.4.0) jsonschema (2.4.0) jupyter (1.0.0) jupyter-client (5.1.0) jupyter-console (5.1.0) jupyter-core (4.3.0) kiwisolver (1.0.1) kombu (3.0.37) leather (0.3.3) lightblue (0.4) llvmlite (0.5.0) lxml (3.6.1) Mako (1.0.6) Markdown (2.6.8) MarkupSafe (0.23) matplotlib (2.2.2) mistune (0.5.1) mock (1.3.0) multipledispatch (0.4.7) munch (2.3.2) mysql-connector-python (2.0.3) MySQL-python (1.2.5) nbconvert (5.2.1) nbformat (4.3.0) networkx (2.1) nltk (3.2.5) nose (1.3.0) notebook (5.0.0) nudepy (0.4) numba (0.19.1) numexpr (2.6.5) numpy (1.14.5) oauth2client (1.4.12) oauthlib (1.1.2) odo (0.3.2) olefile (0.44) openpyxl (2.4.8) osmnx (0.8.1) pandas (0.23.3) pandoc (1.0.2) pandocfilters (1.4.1) paramiko (2.1.1) parsedatetime (2.4) parsekit (1.1.4) parsekit-tools (1.3.0) pathlib2 (2.3.0) patsy (0.3.0) pbr (3.1.1) pdfminer (20110515) pdftables (0.0.4) pep8 (1.6.2) pexpect (4.2.1) pickleshare (0.7.4) Pillow (4.3.0) pip (9.0.1) plotly (2.0.16) ply (3.9) pocketsphinx (0.1.3) polyline (1.3.2) prompt-toolkit (1.0.14) psutil (3.3.0) psycopg2 (2.7.1) ptyprocess (0.5.2) py (1.4.27) pyasn1 (0.1.9) pyasn1-modules (0.0.8) PyAudio (0.2.9) pycosat (0.6.1) pycparser (2.17) pycrypto (2.6.1) pycurl (7.19.5.1) pydruid (0.3.1) pyflakes (0.9.2) Pygments (2.0.2) PyHive (0.3.0) pymavlink (1.1.63) pymc3 (3.0) pyOpenSSL (0.15.1) pyparsing (2.2.0) pyproj (1.9.5.1) pyserial (2.6) pysftp (0.2.9) pytesseract (0.1.6) pytest (2.7.1) python-dateutil (2.7.3) python-editor (1.0.3) python-gflags (3.0.5) python-magic (0.4.11) python-openid (2.2.5) python-slugify (1.2.4) python-twitter (3.3) pytimeparse (1.1.6) pytz (2018.5) pywebhdfs (0.4.1) PyYAML (3.11) pyzmq (14.7.0) qtconsole (4.3.0) Quandl (2.8.9) redis (2.10.3) requests (2.19.1) requests-oauthlib (0.6.1) rope (0.9.4) rsa (3.4.2) Rtree (0.8.3) ruamel-yaml (-VERSION) runipy (0.1.3) s3transfer (0.1.10) sasl (0.2.1) scandir (1.5) scanner (0.0.5) scikit-image (0.11.3) scikit-learn (0.16.1) scipy (0.16.0) seaborn (0.6.0) setuptools (32.1.0) Shapely (1.6.4.post1) simplegeneric (0.8.1) simplejson (3.10.0) six (1.11.0) snowballstemmer (1.2.0) sockjs-tornado (1.0.1) SpeechRecognition (3.6.5) sphero (0.0.1) Sphinx (1.3.1) sphinx-rtd-theme (0.1.7) spyder (2.3.5.2) SQLAlchemy (1.1.11) SQLAlchemy-Utils (0.32.14) sqlparse (0.2.3) statsmodels (0.6.1) subprocess32 (3.5.2) superset (0.18.2) sympy (0.7.6) tables (3.2.0) terminado (0.5) testpath (0.3.1) textblob (0.13.0) Theano (0.7.0) thrift (0.10.0) thrift-sasl (0.2.1) tika (1.15) toolz (0.7.2) tornado (4.2) traitlets (4.3.2) tweepy (3.4.0) twitter-photos (0.3.1) ujson (1.33) unicodecsv (0.14.1) Unidecode (0.4.21) uritemplate (0.6) urllib3 (1.23) uszipcode (0.1.3) virtualenv (15.0.1) wcwidth (0.1.7) webencodings (0.5.1) Werkzeug (0.10.4) wheel (0.29.0) widgetsnbextension (2.0.0) WTForms (2.1) xlrd (1.0.0) XlsxWriter (0.7.3) xlwings (0.3.5) xlwt (1.0.0)

Code that reproduces the issue

def count_and_merge(n, bearings):
    # make twice as many bins as desired, then merge them in pairs
    # this prevents bin-edge effects around common values like 0° and 90°
    n = n * 2
    bins = [ang * 360 / n for ang in range(0, n + 1)]
    count, _ = np.histogram(bearings, bins=bins)

    # move the last bin to the front, so eg 0.01° and 359.99° will be binned together
    count = count.tolist()
    count = [count[-1]] + count[:-1]

    count_merged = []
    count_iter = iter(count)
    for count in count_iter:
        merged_count = count + next(count_iter)
        count_merged.append(merged_count)

    return np.array(count_merged)
# create figure and axes
n = len(places)
ncols = int(np.ceil(np.sqrt(n)))
nrows = int(np.ceil(n / ncols))
figsize = (ncols * 5, nrows * 5)
fig, axes = plt.subplots(nrows, ncols, figsize=figsize, subplot_kw={'projection':'polar'})

for sublist in axes:
       print sublist
axes = [item for sublist in axes for item in sublist]

# plot each city's polar histogram
for ax, place in zip(axes, sorted(places.keys())):
    polar_plot(ax, bearings[place], title=place)

# add super title and save full image
suptitle_font = {'family':'Century Gothic', 'fontsize':60, 'fontweight':'normal', 'y':1.07}
fig.suptitle('City Street Network Orientation', **suptitle_font)
fig.tight_layout()
fig.subplots_adjust(hspace=0.35)
plt.gcf().savefig('images/street-orientations.png', dpi=120, bbox_inches='tight')
plt.close()
JosephRedfern commented 5 years ago

Same issue here. Removing the line:

axes = [item for sublist in axes for item in sublist]

solved it for me.

EDIT: actually, this only seems to occur with two or fewer cities. Beyond 2 cities, the line is required. I assume this is something to do with plt.subplots returning different types/shapes depending on the value of figsize, but am not sure.

gboeing commented 5 years ago

@JosephRedfern yep. It lets you iterate through matplotlib axes to plot each individual histogram on. If you don't have multiple histograms to plot, then you can't iterate.