Python Forum
Remove internal lines donut plot matplotlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove internal lines donut plot matplotlib
#1


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
Reply
#2
use edgecolor = None
or don't supply at all
   
Reply
#3
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!
Reply
#4
i don't see pics on your google drive, but I see the picture I have attached and there are NO lines
Reply
#5
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()
   

here it is with your code
Reply
#6
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).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pick a line in a plot with matplotlib Romain 3 5,627 Feb-28-2023, 11:56 AM
Last Post: get2sid
  Matplotlib scatter plot in loop with None values ivan_sc 1 2,268 Nov-04-2021, 11:25 PM
Last Post: jefsummers
  Matplotlib scatter plot slider with datetime sonny 0 2,952 Feb-05-2021, 02:31 AM
Last Post: sonny
  Matplotlib 2 lines with different markers medatib531 0 1,702 Sep-15-2020, 09:47 PM
Last Post: medatib531
  New to Python & Matplotlib - can I change the plot grid origin to lower left corner? FortyTwo 1 6,181 Aug-22-2020, 08:22 PM
Last Post: matador
  matplotlib creating a scatter plot via PathCollection tpourjalali 0 2,471 Apr-11-2020, 05:59 PM
Last Post: tpourjalali
  MatPlotLib 2d plot of current density? ruben 0 2,202 May-13-2019, 06:47 AM
Last Post: ruben
  Bar Plot with Python ,matplotlib and sqlite3 tables gauravbhardwajee 0 4,956 Sep-25-2018, 06:17 PM
Last Post: gauravbhardwajee
  Draw a square-aspect log-linear plot via matplotlib Antonio 4 8,400 Jun-19-2018, 05:57 PM
Last Post: Antonio
  Change internal representation Samsar 5 3,888 Dec-17-2017, 09:52 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020