26

I'd like to superimpose one plot over another (they are polygons, really in some lat/lon space, using geopandas, but the plot is simply derived from matplotlib)

I have:

figZ, axZ = plt.subplots(1, figsize=(11,8.5))
Sfig = X.plot(ax=axZ, color='white', edgecolor='black', lw=0.7)
Y.plot(ax=axZ, color='white', edgecolor='black', lw=0.7, alpha=0.3)

How do I set Sfig's color to "no-fill" instead of white? The way it is now it "blurs" my Sfig image (X.plot) by the alpha of the Y.plot one. How do I set "color" to actually transparent?

Dervin Thunk
  • 19,515
  • 28
  • 127
  • 217

3 Answers3

50

I don't expect upvotes, but this is what I found as solution. I'll vote up better ones if they exist:

Sfig = X.plot(ax=axZ, facecolor="none", 
              edgecolor='black', lw=0.7)
Dervin Thunk
  • 19,515
  • 28
  • 127
  • 217
1

I know this post doesn't mention seaborn, but I suspect a lot of people end up here asking this question for seaborn also (as I did).

The top answer almost works for seaborn boxplots, you just need to pass it as boxprops.

sns.boxplot(data=data, x=x, y=y, hue=hue, boxprops=dict(facecolor="none"))

NOTE: I emphasise that this solution only works for boxplots. There is a more general was of doing this with the new object API in seaborn.

Michael Hall
  • 2,834
  • 1
  • 22
  • 40
  • 1
    This is not generally true for seaborn and depends on the type of plot you initiate. Depending on the underlying plot structure, you [can often define `edgecolor` and `facecolor`](https://stackoverflow.com/q/63894341/8881141) but in some types, [seaborn overrules the user setting](https://stackoverflow.com/q/66404883/8881141). – Mr. T Feb 05 '22 at 07:04
  • 1
    Ah yes. I just went down a rabbit hole of following github issues around discussing general solutions. I will emphasise that my solution is only relevant to boxplots. – Michael Hall Feb 06 '22 at 01:42
0

To disable facecolor just set with the value (0, 0, 0, 0), i.e.,

Sfig = set_facecolor((0,0,0,0))