1

I can't figure out why the below code returns two subplots. If I comment out the first line (plt.subplots), I get one single map. But when it's included I get a huge whitespace first, just as I would if I specified 2 subplots and only put data in the second. I can't understand why.

This is not a reproducible example, what I'm looking for is if it's something my code is lacking.

fig, ax = plt.subplots(figsize=(4, 4))
#matplotlib.rcParams["figure.dpi"] = 250
ax.axis('off')

ax=lan.plot(color='lightgrey', edgecolor='black', linewidth=0.3)
ax.set_facecolor("lightskyblue")
ax=geo_df1.plot(edgecolor='black', column=geo_df1.rel_grp, ax=ax, cmap=my_cmp, linewidth=0.3, categorical=True)

fig.show(ax)

1 Answer 1

1

The problem is you are not passing the subplot ax to in lan.plot.

Change this line:

ax=lan.plot(color='lightgrey', edgecolor='black', linewidth=0.3)

To this:

ax=lan.plot(color='lightgrey', edgecolor='black', linewidth=0.3, ax=ax)

For example, this code:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

df = pd.DataFrame({
   'pig': [20, 18, 489, 675, 1776],
   'horse': [4, 25, 281, 600, 1900]
   }, index=[1990, 1997, 2003, 2009, 2014])

fig, ax = plt.subplots(figsize=(4, 4))
ax.axis('off')

ax = df.plot()
ax = df.plot(ax=ax)

fig.show(ax)

Outputs:

Out1

But changing to this:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

df = pd.DataFrame({
   'pig': [20, 18, 489, 675, 1776],
   'horse': [4, 25, 281, 600, 1900]
   }, index=[1990, 1997, 2003, 2009, 2014])

fig, ax = plt.subplots(figsize=(4, 4))
ax.axis('off')

ax = df.plot(ax=ax)
ax = df.plot(ax=ax)

fig.show(ax)

Outputs:

Out2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.