Python Forum

Full Version: Remove internal lines donut plot matplotlib
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


Hi,

I have this code (most of them getting from https://python-graph-gallery.com/163-don...subgroups/) and it works good, but I would like to delete the internal lines that separate each class/box.

Code:

import matplotlib.pyplot as plt

subgroup_names=[i for i in range(16)]
subgroup_names=subgroup_names[::-1]
subgroup_size= 16*[5]
 
# Create colors
a, b, c=[plt.cm.Reds, plt.cm.RdYlGn, plt.cm.Blues]

#Probamos hacer una lista de colores para poder invertirla
colors=[b(0.4), b(0.42), b(0.44), b(0.46), b(0.47), b(0.49), b(0.51), b(0.53), b(0.55), b(0.56), b(0.58), b(0.6)]
 
# First Ring (outside)
fig, ax = plt.subplots(figsize=(15,10))

#fig.patch.set_facecolor('white')
ax.axis('equal')
# Remove grid lines (dotted lines inside plot)
ax.grid(False)
# Remove plot frame
ax.set_frame_on(False)
# Pandas trick: remove weird dotted line on axis

#mypie, _ = ax.pie(group_size, radius=1.3, labels=group_names, colors=[a(0.6), b(0.6), c(0.6)])
#plt.setp( mypie, width=0.3, edgecolor='red')
 
mypie2, _ = ax.pie(subgroup_size, radius=0.9, labels=subgroup_names, labeldistance=0.7,
                   colors=[a(0.9), a(0.8), a(0.7), a(0.6), a(0.5), a(0.4), a(0.3), a(0.2), a(0.1), a(0.1), a(0.1), a(0.1)])
plt.setp( mypie2, width=0.1, edgecolor='none')
plt.margins(1,1)

# Second Ring (Inside)

mypie3, _ = ax.pie(subgroup_size, radius=0.8, 
                   colors=[c(0.9), c(0.8), c(0.7), c(0.6), c(0.5), c(0.4), c(0.3), c(0.2), c(0.1), c(0.1), c(0.1), c(0.1)])
plt.setp( mypie3, width=0.1, edgecolor='none')
plt.setp(mypie3,  visible=True)
plt.margins(1,1)

# Third Ring (Inside)
mypie4, _ = ax.pie(subgroup_size, radius=1, 
                   colors=colors[::-1])
plt.setp( mypie4, width=0.1, edgecolor='none')
plt.margins(1,1)

# show it
#plt.savefig(r'/delete/prdavid.jpeg', dpi=1500)
plt.show()
Output:

[Image: open?id=1ZU6MR3PWhHgCbhiBAHR1x4CafZdQt1-1]
[Image: open?id=1cYBSL8rFL-93yzNjJDzEJAI_d2b7Kdvx]


You can see in the zooming image, the lines I would need to delete.

Thanks so much!

Ps. I can't see the images in the preview. Just in case, I paste the links to google drive here:

https://drive.google.com/open?id=1cYBSL8...I_d2b7Kdvx
https://drive.google.com/open?id=1ZU6MR3...CafZdQt1-1
use edgecolor = None
or don't supply at all
[attachment=313]
Hi buran,

Nope, that doesn't work. That way is how is made the picture I upload to Google Drive. I do remove the edgeline of each class, but still get that annoying lines. I believe that they comes with the axis, but still don't figure out how to remove them.

Thanks anyway!
i don't see pics on your google drive, but I see the picture I have attached and there are NO lines
actually, even your code (with edgecolor='none') produce the result
import matplotlib.pyplot as plt
 
subgroup_names=[i for i in range(16)]
subgroup_names=subgroup_names[::-1]
subgroup_size= 16*[5]
 
# Create colors
a, b, c=[plt.cm.Reds, plt.cm.RdYlGn, plt.cm.Blues]
 
#Probamos hacer una lista de colores para poder invertirla
colors=[b(0.4), b(0.42), b(0.44), b(0.46), b(0.47), b(0.49), b(0.51), b(0.53), b(0.55), b(0.56), b(0.58), b(0.6)]
 
# First Ring (outside)
fig, ax = plt.subplots(figsize=(15,10))
 
#fig.patch.set_facecolor('white')
ax.axis('equal')
# Remove grid lines (dotted lines inside plot)
ax.grid(False)
# Remove plot frame
ax.set_frame_on(False)
# Pandas trick: remove weird dotted line on axis
 
#mypie, _ = ax.pie(group_size, radius=1.3, labels=group_names, colors=[a(0.6), b(0.6), c(0.6)])
#plt.setp( mypie, width=0.3, edgecolor='red')
 
mypie2, _ = ax.pie(subgroup_size, radius=0.9, labels=subgroup_names, labeldistance=0.7,
                   colors=[a(0.9), a(0.8), a(0.7), a(0.6), a(0.5), a(0.4), a(0.3), a(0.2), a(0.1), a(0.1), a(0.1), a(0.1)])
plt.setp( mypie2, width=0.1)
plt.margins(1,1)
 
# Second Ring (Inside)
 
mypie3, _ = ax.pie(subgroup_size, radius=0.8,
                   colors=[c(0.9), c(0.8), c(0.7), c(0.6), c(0.5), c(0.4), c(0.3), c(0.2), c(0.1), c(0.1), c(0.1), c(0.1)])
plt.setp( mypie3, width=0.1, edgecolor=None)
plt.setp(mypie3,  visible=True)
plt.margins(1,1)
 
# Third Ring (Inside)
mypie4, _ = ax.pie(subgroup_size, radius=1,
                   colors=colors[::-1])
plt.setp( mypie4, width=0.1, edgecolor='none')
plt.margins(1,1)
 
# show it
#plt.savefig(r'/delete/prdavid.jpeg', dpi=1500)
plt.show()
[attachment=314]

here it is with your code
Yes, that my output. But if you zoom in the image, you could notice a small dashed grey line (in the border of every class).