Pie chart labels matplotlib. Plot a Pie Chart in Matplotlib.

And then remove the percentage text objects. DataFrame({'Q10_Ans':['Boomer May 8, 2021 · Advertisements. pie(data, autopct=my_autopct, colors=colors, labels=labels) Note, however, that the legend by default is being generated from the first passed labels, so you'll need to pass all values explicitly to keep it intact. Using the pie () function plot the pie chart by passing the values list as a parameter. If you're looking to plot a piechart from a DataFrame, and want to display the actual values instead of percentages, you could reformat autopct like so: values=df['your_column']. plot. pie(sizes, colors=colors, startangle=-270) with: patches, texts = plt. If not None, is a len(x) array which specifies the fraction of the radius with which May 18, 2019 · matplotlib. Sep 11, 2018 · The pie function takes only 1 value for the size of each pie, and you'll have to explicitly specify the label as 'label = x ['users']' you can find a more detailed understanding for the parameters Here ! Therefore, your code would be like this: plt. That's why I decided to use radius. Pass the labels and the values as input to the function to create a pie chart counterclockwise, as in the example below. Label or position of the column to plot. subplots_adjust (bottom=0. Optionally, you can specify the coordinate system of xy and xytext with one of the following strings for xycoords and textcoords (default is 'data'): Note: for physical Nov 14, 2021 · 6. Plot a pie chart for each column. Code explanation. Create random Labels. title() function adds a title to the chart and plt. Nov 8, 2013 · Maybe add these information to the legend. This example sets startangle = 90 such that everything is rotated counter-clockwise by 90 degrees, and the frog slice starts on the positive y-axis. The label will be placed inside the wedge. labels = u'Participaram', u'Não participaram'. You can change pctdistance (distance between percentage) and labeldistance (distance between labels) parameter to suit your needs too. Parameters: x1D array-like. update_traces to set other parameters of the chart (you can also use fig. But with that reduction my labels become not clear and less readable (even if to increase the size of labels). show() Mar 20, 2015 · 6. You can determine slice sizes, which segments should stand out from the center (explode), their respective labels, and even their colors. Dec 2, 2021 · Assuming that the order of the annotations can be different, we can reorder the numbers into the order of large and small, and change the order of the labels accordingly. pyplot as plt x = [15, 30, 55] labels = [1, 2, 3] plt. pie (total Plot a pie chart. matplotlib - pie chart label customize with percentage. This approach depends on the data and may be limited to this task. The plt. pyplot. 2? 4. From pyplot. pie(x,labels=labels) plt. See the tutorial for many examples with options for the arrows and a bounding box around the text. If you want to show the % symbol on the pie chart, you have to write/add: May 18, 2019 · Welcome to the matplotlib bakery. To specify fractions direction of the pie chart, you must set the counterclock parameter to True or False (value is True by default). 1, 0. 410 seconds) Sphinx. Pandas: a library to prepare data for plotting. Pip: package management system (it comes with Python) Jupyter Notebook: an online editor for data visualization. pie documentation:. You may position the texts manually using a predefined list of pctdistances. The labels parameter must be an array with one label for each wedge: May 18, 2019 · In addition to the basic pie chart, this demo shows a few optional features: Note about the custom start angle: The default startangle is 0, which would start the "Frogs" slice on the positive x-axis. update Mar 29, 2022 · 1. 0f}'. The startangle parameter rotates the pie chart by the specified number of degrees. get_position() == pos] # calculate the angle with respect to the center of the pie. Make a pie chart of array x. pie(sizes The above code is a basic example of how to set labels in a pie chart. patches as mpatches. pie(sizes, labels=labels) Each slice of the pie chart is a patches. figure(figsize=(15,15)) for i in range(len(sizes)): s = sizes[i] plt. set_rmax(2) ax. pyplot as plt import numpy as np r = np. Plot a pie chart. centered at the "axis" of the slice). ···. apply(list). label: This parameter is the sequence of strings providing the labels for each wedge. This function wraps matplotlib. Add a legend using plt. png, png) If a plot does not show up please check Troubleshooting. ) when assigning to labels. I would like to only plot the top 10 countries by values (by highest %) and within the plot, calculate the remaining countries % value and give it Apr 21, 2017 · plt. Apr 12, 2021 · In this tutorial, we'll cover how to plot a Pie Chart in Matplotlib. answered Apr 21, 2017 at 0:37. %matplotlib inline. k = [7,15] labels = 'Strongly and Mostly \n Agree', 'Strongly/Mostly Disagree \n and In the Middle'. Aug 25, 2018 · no, check well, all the labels are not centered, so you understand me draw a line that divides the slice in half, and above that line the text is drawn, that is, the base of the text is in the line that divides Each slice in the middle, in the case that the slice is small, the effect is noted, so the general idea of the solution is to calculate the height of the text, calculate the Matplotlib logo; Multipage PDF; Multiprocessing; Packed-bubble chart; Patheffect Demo; Print Stdout; Rasterization for vector graphics; Set and get properties; SVG Filter Line; SVG filter pie; Table Demo; TickedStroke patheffect; transforms. pyplot as plt sizes = [3, 193, 126, 16, 6, 1, 0] labels = ['<18', '18-24', '25-34', '35-44', '45-54', '55-60', '>60'] And then you give these arguments to following function. offset_copy; Zorder Demo; 3D plotting. 7 using the example shown here. ). import pandas as pd import numpy as np from matplotlib import pyplot as plt def label_function(val): return f'{val / 100 * len(df The pie chart drawn using the Matplotlib. linewidth'] = 2. Matplotlib center alignment for pie chart labels. Next, plot the pie chart using Matplotlib. df. Change position of label of Matplotlib pie chart. And the biggest problem is that with reduction of radius there is still a lot of space below and under the autopct enables you to display the percentage value of each slice using Python string formatting. pie () 方法语法格式如下: matplotlib. set_rlabel_position(-22. autotexts: A list of Text instances for the numeric labels. Note that the xlabel "XLabel1 1" would normally be much closer to the x-axis, "YLabel0 0" would be much closer to the y-axis, and title "Title0 0" would be much closer to the top of their respective axes. Jan 5, 2020 · Welcome to the matplotlib bakery. We can keep all the labels in a separate rectangular space which makes the figure cleaner. Now it's time for the pie. pie(sizes[1:], labels=labels[1:], colors=[colours[key] for key in labels[1:]]) This works to create the plot: Here we see that the labels are represented by the same colours across both plots, as desired. reset_index() To add labels, pass a list of labels to the labels parameter. If you want a copy and not just the reference, replace it with list(. Instead of . pyplot can be customized of its several aspects. deg2rad(3. align_labels wraps the x and y label functions. groupby('Singapore')['Entity']. Starting with a pie recipe, we create the data and a list of labels A pie plot is a proportional representation of the numerical data in a column. Kushal Naidu. labels=('Really really really really really really long label 1', 'Really really really really really really long label 2', 'Really really really really really really long label 3') values=(30,50,40) fig = plt. 2. But I don't see a solution with a pie Jun 5, 2020 · I saw a sample from the internet to build a simple pie chart from Matplotlib but not sure how to embed it plt. legend() use. Create slices and activities using numpy. Sep 2, 2017 · Changing the color of labels on the chart. pie function. Import necessary libraries: import pandas as pd and import matplotlib. arange(3)*4) May 2, 2023 · colors: This parameter is the sequence of matplotlib color args through which the pie chart will cycle. ) # select all labels with that position. 1. If you want the labels sorted, you could first call sizes = sizes. e. eg. figure(figsize = (4,4)) ax11 = fig. 5) # Move radial labels The goal is to create a pie chart based on the above data. Matplotlib: a plotting library. The fractional area of each wedge is given by x/sum(x). # The slices will be ordered and plotted counter-clockwise. DataFrame. Add the following at the top of your script: import matplotlib as mpl mpl. 实例. change the plot background color to a different color. sizes = [215, 130] Mar 6, 2019 · I try to plot a pie chart using Python 3 Matplotlib v2. 1f%%', shadow=False, startangle=90) fix_labels(autopct, sepfactor=3) fix_labels(labels, sepfactor=2) This works well as-written if you only have a few labels overlapping. Therefore, when printing on console, you might have thought that this is a list, while it is just a long string. Demo of a line plot on a polar axis. autopct = '%. new_df = consumption. 8, . 10. The best way to tackle the problem of overlapping labels in the pie chart is to use the labels separately in the plot. import numpy as np. With the above code, the result is a visually pleasing pie chart. labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'. Line 1: We import the pie() and show() functions from matplotlib. 5, 1, 1. You can use the template below to plot the chart: There are a couple of ways you can change the font size of the labels. Output: Explanation: Import the matplotlib package to access the functions which are used to plot a pie chart. Since the data does not have any labels, creating a legend requires us to define the icons and labels. Customize labels, explode, and other parameters as needed. sort_index (). r * 0. In the example below, we first create a pie chart with px,pie, using some of its options such as hover_data (which columns should appear in the hover) or labels (renaming column names). 1f Aug 5, 2008 · This offers a partial workaround, but it’s nowhere near so good as it would be to move the labels inward so they don’t get cut off (while keeping the pie graph at a preferred size for the graph itself). If you have lots of categories it can be cumbersome to manually set a colour for each category Dec 14, 2020 · The matplotlib. Text object which are return type of function plot. pie(k, labels= labels) Apr 24, 2018 · Remove the str(. StepsInitialize a variable n=20 to get a number of sections in a pie chart. index so both will have the same order. legend(labels=labels) plt. Jun 3, 2023 · Step 2: Making sure, a pie chart is needed. 2f' # display the percentage value to 2 decimal places. import seaborn as sns. The text is drawn horizontally. import pandas as pd. For example, autopct = '%. pie (subplots=True, labeldistance=None, legend=True) From the docs: labeldistance: float or None, optional, default: 1. The pie function is shown below; we'll cover some of the more commonly used parameters through a worked example. Nov 18, 2016 · 2. 12. To create a nested pie chart, we’ll need the following: Python installed on your machine. set_facecolor('lightgrey') or. axis ("equal") pie = plt. pyplot as plt # Create a dataframe with the data data = {'Product': ['Product A', 'Product B', 'Product C', 'Product D'], 'Sales': [350, 450, 300, 600]} df = pd. The 'tight' setting rescales the canvas to accommodate all content and happens before wrapping. count() data = pd. pyplot as plt fig, ax = plt. pie (x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0. pyplot as plt labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' sizes = [15, 30, 45, 10] fig, ax = plt. If sum(x) < 1, then the values of x give the fractional area directly and the array will not be normalized. dup_labels = [l for l in labels if l. subplots (figsize= (4,4)) plt. Any ways of fixing this issue even if it changes layout are appreciated. set_rticks([0. With original size the pie was huge, all over the screen. pie(x['number'],labels = x['users']) answered Sep 11, 2018 at 11:59. . gca (). All you have to do is use kind='pie' flag and tell it which column you want (or use subplots=True to get all columns). # data = df. pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0. DataFrame(data) # Plot the pie chart with labels and Mar 21, 2022 · Pandas has this built in to the pd. subplots() ax. Add labels to the pie chart with the labels parameter. The rotation is counter clock wise and performed on X Axis of the pie chart. Basic pie chart Pie Demo2 Bar of pie Nested pie charts Labeling a pie and a donut Bar chart on polar axis Polar plot Polar Legend Scatter plot on polar axis Using accented text in matplotlib Scale invariant angle label Annotating Plots Arrow Demo Auto-wrapping text Composing Custom Legends Date tick labels Custom tick formatter for time series Jan 26, 2023 · help(pie) says: *autopct*: [ *None* | format string | format function ] If not *None*, is a string or function used to label the wedges with their numeric value. We will create a pie and a donut chart through the pie method and show how to label them with a legend as well as with annotations. cos(ang*np. Customized Histogram with Watermark. Step 3: Plot the Pie Chart using Matplotlib. 3) total = [13,87] plt. Jul 24, 2022 · Let's explore how to use Matplotlib function pie() to draw pie charts with customized colors, text, and percent labels. figure(figsize=(3, 3), dpi=72) plt. show(). Dec 2, 2015 · labels = [n if v > data. show() This gives the error: Apr 1, 2013 · Here is some sample code that I'd like a fix for: import numpy as np. value_counts(dropna=True) plt. The label inside the plot was a result of radius=1. Where to go next#. How to present the labels on the pie in pie chart in python? 0. Pass the values for the pie chart as a list. pie. pie ¶. Sep 3, 2023 · Steps to add label to pie plot. pie() for the specified column. 我们可以使用 pyplot 中的 pie () 方法来绘制饼图。. 1f' # display the percentage value to 1 decimal place. subplots(subplot_kw={'projection': 'polar'}) ax. Line 2: We import the array() function from NumPy library. plot(kind='pie', subplots=True, figsize=(6, 4)) My dataframe consists of two columns - Country and Value (% distribution) and has about 25 countries listed. It sets the fruits as index labels and uses the ‘Quantity’ column as the values for the pie chart. get_cmap("tab20c") outer_colors = cmap(np. . Sep 1, 2020 · Here is an approach using pandas:. I am having problems generating a graph which doesn't overlap with text both for percentages and country codes, I am using python3 matplotlib, see image below. The full doucmentation is available here as a reference. pie(s) plt. pie(x) plt. ang = (patch. Return value: If autopct is not None, return the tuple (patches, texts, autotexts), where patches and texts are as above, and autotexts is a list of Text instances for the numeric labels. If it is a function, it will be called. When you call ax. Check out Plot types to get an overview of the types of plots you can create with Matplotlib. figure() ax=fig. Plot a Pie Chart in Matplotlib. 4. color'] = 'r'. Retrieve a named colour map and "hand-pick", using a numbered range, suitable colors. pie(x, explode= None, labels= None, colors= None, Jul 16, 2019 · You can either: 1. pie(df, labels=my_labels, autopct='%1. ¶. pie it returns a tuple of (patches, texts, autotexts Jul 10, 2024 · Here’s an example code snippet that demonstrates how to add labels and percentages to a pie chart: Code: import matplotlib. groupby("Q10_Ans")["Q4_Agree"]. sum()/100), startangle=90) Dec 26, 2021 · The area of the slices is equal to the percentage of the parts of the data. pie keyword labeldistance to remove the wedge labels. import (Source code, 2x. Prepare your data in a pandas DataFrame. 2D Histogram (Hexbin Plot) Create a Basic Histogram in Matplotlib. The index picking in inner_colors matches hues for a larger numbers of data points in the inner circle: cmap = plt. The radial distance at which the pie labels are drawn. title ('How to spot intellectuals on TV') plt. change the textprops color to something different: textprops={'color':"blue", 'size': 10, 'weight':'bold'} You can easily manage the font size, style and color using the textprops argument in the ax. Here is my code: import matplotlib. pie(sizes, labels=groups, autopct='%1. The wedges of the Pie chart is returned as: patches: A sequence/ list of patches wedge instances texts: A list of the label Text instances. sizes = [15, 30, 45, 10] Feb 14, 2018 · You can remove the labels argument from the pie and add it to the legend. Jan 9, 2024 · Here we will see different methods of Plotting Histogram in Matplotlib in Python: Basic Histogram. Mar 29, 2021 · I don't know the data structure of your data, so I made a sample data and created a pie chart. 7 * np. The syntax is given below: matplotlib. pyplot as plt fig, ax= plt. You can use labels = sizes. Dec 19, 2022 · Overlapping labels in matplotlib pie chart. Default, they would be sorted in order of appearance. Matplotlib can wrap text automatically, but if it's too long, the text will be displayed slightly outside of the boundaries of the axis anyways. pie() does not seem to have this attribute. import matplotlib. In the code below we've listed a few Apr 15, 2014 · Here is an example with some random data replicating the occurrence of overlapping labels: offset = np. theta1) / 2. Rune_V_Sjoen March 23, 2010, 3:33pm 1. The pie matplotlib function Given a set of categories or groups with their corresponding values you can make use of the pie function from matplotlib to create a pie chart in Python. We can change the color of labels and percent labels by set_color() property of matplotlib. legend(labels=labels) Complete example: import matplotlib. plt. Note: Auto-wrapping does not work together with savefig(, bbox_inches='tight'). The pie chart sometimes cuts off even relatively short labels that extend beyond the edge of the image (. Additionally, you may specify a text point xytext=(x, y) for the location of the text for this annotation. 7 is the distance from the center. We will create a pie and a donut chart through the pie method and show how to label them with a legend as well as with annotations . Jan 8, 2020 · Override Matplotlib pie chart percentage labels to a specific value that doesn't sum to 100%. sum() * 0. We can use the legend function of the pyplot library for the same. plot(). format(x*values. A tutorial on creating pie charts in python with Matplotlib, including adding labels, changing the styles, and using custom colors. The only mandatory argument is the data we'd like to plot, such as a feature from a dataset: [ ] You must specify an annotation point xy=(x, y) to annotate this point. rcParams['text. 0. For your need, you must replace: patches, texts = plt. 8, 0. subplots(1,2, figsize=(10,5)) Set the figure size to 10 - width and 5 - height. #. Parameters: yint or label, optional. fig =plt. How to avoid overlapping of labels autopct in a Matplotlib pie chart - To avoid overlapping of labels and autopct in a matplotlib pie chart, we can follow label as a legend, using legend () method. Multiple Histograms with Subplots. pi/180) Apr 14, 2024 · Steps to customize pie plot. Tried to add it according to official documentation ( colors=[colours[key] for key in labels]) ax[1]. Aug 9, 2022 · Pie charts are generated using the matplotlib. As usual we would start by defining the imports and create a figure with subplots. For example: There are many other Matplotlib objects that can be used in this way. Matplotlib allows for extensive customization. legend() and display the plot with plt. x = patch. for n, v in zip(df. show() This gives the error: Jan 14, 2017 · 4. If the need for a pie chart is unambiguously determined, let's proceed to place the legend. 0 Or you can modify the labels after they have been created. pandas pie charts subplots labels overlap with slice labels. Pie charts represent data broken down into categories/labels. And I am trying to avoid using a legend. sizes = [50,50] plt. Sep 24, 2012 · Hi, I have pie charts with relatively long texts assigned to each slice of the pie. 8). pie(sizes, counterclock=False, colors=colors, startangle=-270) answered Feb 6, 2018 Aug 24, 2021 · legend=True adds the legend; title='Air Termination System' puts a title at the top ylabel='' removes 'Air Termination System' from inside the plot. sort_values (). You could loop through the labels and percentages, and append the percentage text to the label text. May 30, 2018 · 9. 8]) labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' fracs = [15, 30, 45 Figure. size'] = 9. Create the figure and pair axes - f, axes = plt. 6, shadow May 5, 2020 · pie chart label overlap. 2-4build1 on Ubuntu 18. You might want to move autotexts of narrow wedges from the center of the wedge along the radius: # the angle at which the text is located. pyplot as plt import numpy as np import pandas as pd data Oct 18, 2015 · The example code for a pie chart is given here: figure(1, figsize=(6,6)) ax = axes([0. add_subplot(111) Explore the world of writing and self-expression on Zhihu's column platform, where creativity meets freedom. pie(). pyplot module. In this case, we can compose a legend using Matplotlib objects that aren't explicitly tied to the data that was plotted. In matplotlib, the pie () function is used to create a pie chart. Wedge object; therefore in addition to the customizations shown here, each wedge can be May 8, 2018 · Matplotlib Pie Chart Labels Alignment. #def pieChart() # Data to plot. plot(theta, r) ax. Bar chart on polar axis May 7, 2020 · How to avoid pie chart labels overlapping in MatPlotLib ver. Nov 3, 2010 · Global default colors, line widths, sizes etc, can be adjusted with the rcParams dictionary: import matplotlib. pie() function. Customizing a pie chart created with px. A complete list of params can be found here. Matplotlib 饼图 饼图(Pie Chart)是一种常用的数据可视化图形,用来展示各类别在总体中所占的比例。. Here is the code I am using: import matplotlib. Line 5: We create a list variable my_labels which will serve as the value for the label parameter. Nov 26, 2022 · Creating Legends. pyplot as plt. This code snippet creates a simple pie chart from a pandas DataFrame called df. Apr 24, 2020 · import matplotlib. Or, to have them sorted by value: sizes = sizes. Communitymatplotlib-users. arange(0, 2, 0. Bar chart on polar axis. 0. 1. You'll learn to use parameters such as autopct, textprops, colors, startangle, counterclock, labeldistance, pctdistance, shadow, and explode. add_subplot(111) # Data to plot. Please modify your code to follow this. I am trying to produce a Matplotlib pie chart in Python 2. Showing one label on pie chart pandas. 2 else ''. How can I improve the rotation of fraction labels in a pyplot pie chart. rcParams['lines. Starting with a pie recipe, we create the data and a list of labels 2. Labeling a pie and a donut. For further tuning, we call fig. 6, shadow=False, May 6, 2015 · Using pandas you can still use the matplotlib. axis('equal') plt. show Removing labels from pie chart moves the legend box. # new coordinates of the text, 0. pie returns the wedges and lists of text objects for the labels and the percentages. change matplotlib style (optional) Create example DataFrame. theta2 + patch. There may be a smarter way to reorder the data. 01) theta = 2 * np. Stacked Histogram. In this way the text would not overlap other text of adjacent slices (or at least if the text starts far enough from the pie). The resulting pie will have an empty wedge of size 1 - sum(x). 5 Dec 7, 2020 · The problem of my chart is next. Apr 5, 2022 · If you're dealing with your challenges only, first group them to aggregate the number of labels. However, it still overlaps, so get the current label position and change the position of the overlapping label. index, data)] ax. pctdistance: This parameter is the ratio between the center of each pie slice and the start of the text generated by autopct. The wedges are plotted counterclockwise, by default starting from the x-axis. ax. Plot the pie chart using df. Shadow effect can be provided using the shadow parameter of the pie () function. pie () functions return a pie chart plot in Python. The example below is a bit Nov 27, 2022 · Here is an example, where the labels are positionned manually in Data coordinates, i. Data. Apr 25, 2023 · If you want to create a pie chart, you need list of values and list of labels. To plot a pie chart in Matplotlib, we can call the pie() function of the PyPlot or Axes instance. Customized Histogram with Density Plot. The wedge sizes. 14. Total running time of the script: (0 minutes 1. If it is a format string, the label will be ``fmt%pct``. edited Apr 21, 2017 at 1:28. Hello, I am having some issues generating pie charts, when some of the slices become very small, their labels will draw on top of each other, making it impossible to distinguish between them. matplotlib. pi * r fig, ax = plt. This will only be returned if the parameter autopct is None. The grouped data frames are targeted for the pie chart. This will automatically add the labels for you and even do the percentage labels as well. Plot 2D data on 3D plot; Demo of 3D bar charts; Create 2D bar Polar plot. 6. text. legend() has two main arguments to determine the position of the legend. fig. You can dynamically changet the rc settings. If not None, is a len(x) array which specifies the fraction of the radius with which Apr 9, 2021 · You could use annotations based on the wedges' angles. In many cases pie charts are not the best way to convey information. Putting it all together (besides the special chars - I had some problems activating TeX), try the following code: # -*- coding: UTF-8 -*-. Placing the legend. Line 4: We use the array() method to create a data array data_set. explodearray-like, default: None. 1, . If no column reference is passed and subplots=True a pie plot is drawn for each numerical column independently. You could also adjust the line width after you draw your pie chart: from matplotlib import pyplot as plt. The pie function does not take lists or arrays as input for the pctdistance argument. Feb 7, 2019 · which results in a plot with no labels at all, and finally I tried putting my plt. They're an intuitive and simple way to visualize proportional data - such as percentages. 3. pie() call into a for loop, but even the simplest version of that didn't work. Mar 23, 2010 · Overlapping labels in pie charts. rcParams['font. Import libraries - matplotlib and pandas. Everything seems to be ok except labels - they are missing. 5, 2]) # Less radial ticks ax. When using str() on a list, it makes the whole list as string, including the square-brackets. Hot Network Feb 2, 2018 · I have created a matplotlib pie chart: df. Instead, I would like to have it rotated at the same angle as the slice itself (i. pie(<actual_values>, colors = colors, autopct= lambda x: '{:. plot(kind='pie', ). Jan 5, 2020 · In addition to the basic pie chart, this demo shows a few optional features: Note about the custom start angle: The default startangle is 0, which would start the "Frogs" slice on the positive x-axis. the center of the pie is (0,0) coordinate. I think you mean "overlap" instead of "overflow". Mar 24, 2016 · For other chart/graph types in Matplotlib there is an argument called align where you can set it to center, however, plt. Mar 4, 2024 · The output of this code snippet is a pie chart visualization of the quantity of fruits sold. plot(kind='pie') So use it like: wedges, labels, autopct = ax1. legend(pie[0], labels, loc="upper corner", bbox_to_anchor = (1,1)) Play around with the bbox_to_anchor to shift it around. 2. Define two axes in the figure to draw every pie chart separately and for automatic adjust use tight_layout: import matplotlib. ou kr hw yy gq lo kj tb zh uv