Issue
I would like to draw pie charts on a map using Basemap and plt.pie. What I want in the end, is that the pie charts are covering the overlapping country borders/coastlines. However, the resulting pie charts are transparent, i.e. I can still see the country borders/coastlines under the pie charts. Below is the resulting figure.
I thought it's due to the transparency of the pie chart, so I set wedgeprops={'alpha':1}, but the pie chart is still transparent.
Any ideas on what I should do? Thank you.
My code is given below:
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap as Basemap
m = Basemap(
projection='cyl',
llcrnrlon=-10,
llcrnrlat=50,
urcrnrlon=5,
urcrnrlat=60,
resolution='l')
m.drawcountries()
m.drawcoastlines()
attributes = [1,5,2]
a = plt.pie(
attributes,
center=(m(-2.78, 53.98)),
colors = ["tab:purple", "tab:blue", "tab:red"],
# wedgeprops={'alpha':1},
radius= 2)
axis = plt.gca()
axis.set_xlim([-10, 5])
axis.set_ylim([50, 60])
Solution
You need to set zorder
properly.
m.drawcountries(zorder=-10)
m.drawcoastlines(zorder=-11)
This places the map's layers below the pie chart.
Answered By - swatchai
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.