Search code examples
pythonmatplotliblinepie-chart

Plotted lines gets compressed when plot pie chart with matplotlib.pyplot


In my program first I draw a tree (graph with no cycles) plotting just lines. As yo can see in the figure

Figure of ploted lines

My problem is that when I plot a pie chart over the same figure, all the plots and pie chart gets compresed, and the box disapears, as you can see in the next figure

Figures compresed after ploting pie chart

My code basically is:

from mathplotlib import pyplot as plt plt.figure() # Plottin a straight line from (0,0) to (1,1) in the (x,y) plane X=[0,1] Y=[0,1] plt.plot(X,Y) # Plotng a pie chart plt.pie([100],radius=0.5,center=(1/4,3/4)) Why it happends? How can I fix it?


Solution

  • The keyword Frame in the call to pie() is what you are after.

    from matplotlib import pyplot as plt
    X = [0, 1]
    Y = [0, 1]
    plt.plot(X, Y, color='black', zorder=100)
    plt.pie([1], radius=0.5, center=(0.5, 0.5), frame=True)
    plt.show()
    

    enter image description here