0% found this document useful (0 votes)
6 views

Matplotlib

Uploaded by

saraga
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Matplotlib

Uploaded by

saraga
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

In [ ]:

What is Matplotlib?
Matplotlib is a low level graph plotting library in python that serves as a

In [ ]:
The plot() function is used to draw points (markers) in a diagram.

By default, the plot() function draws a line from point to point.

The function takes parameters for specifying points in the diagram.

Parameter 1 is an array containing the points on the x-axis.

Parameter 2 is an array containing the points on the y-axis.

If we need to plot a line from (1, 3) to (8, 10),


we have to pass two arrays [1, 8] and [3, 10] to the plot function.

In [2]:
import matplotlib.pyplot as plt
import numpy as np

xpoints = np.array([1, 8])


ypoints = np.array([3, 10])

plt.plot(xpoints, ypoints)
plt.show()

In [ ]:
Plotting Without Line
To plot only the markers, you can use shortcut string notation parameter 'o

In [3]:
#Draw two points in the diagram, one at position (1, 3) and one in position

import matplotlib.pyplot as plt


import numpy as np

xpoints = np.array([1, 8])


ypoints = np.array([3, 10])

plt.plot(xpoints, ypoints, 'o')


plt.show()
In [ ]:
Multiple Points
You can plot as many points as you like,
just make sure you have the same number of points in both axis.

In [4]:
#Draw a line in a diagram from position (1, 3) to (2, 8) then to (6, 1) and

import matplotlib.pyplot as plt


import numpy as np

xpoints = np.array([1, 2, 6, 8])


ypoints = np.array([3, 8, 1, 10])

plt.plot(xpoints, ypoints)
plt.show()

In [ ]:
Default X-Points
If we do not specify the points in the x-axis,
they will get the default values 0, 1, 2, 3, (etc. depending on the length

So, if we take the same example as above, and leave out the x-points,
the diagram will look like this:

In [5]:
#Plotting without x-points:

import matplotlib.pyplot as plt


import numpy as np
ypoints = np.array([3, 8, 1, 10, 5, 7])

plt.plot(ypoints)
plt.show()

In [ ]:
Markers
You can use the keyword argument marker to emphasize each point with a spec

In [10]:
#Mark each point with a circle:

import matplotlib.pyplot as plt


import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o')


plt.show()

In [ ]:
Marker Description
'o' Circle
'*' Star
'.' Point
',' Pixel
'x' X
'X' X (filled)
'+' Plus
'P' Plus (filled)
's' Square
'D' Diamond
'd' Diamond (thin)
'p' Pentagon
'H' Hexagon
'h' Hexagon
'v' Triangle Down
'^' Triangle Up
'<' Triangle Left
'>' Triangle Right
'1' Tri Down
'2' Tri Up
'3' Tri Left
'4' Tri Right
'|' Vline
'_' Hline

In [ ]:
Format Strings:
fmt
You can use also use the shortcut string notation parameter to specify the

This parameter is also called fmt, and is written with this syntax:

marker|line|color

In [9]:
#Mark each point with a circle:

import matplotlib.pyplot as plt


import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, 'o:r')
plt.show()

In [ ]:
Line Reference

'-' Solid line


':' Dotted line
'--' Dashed line
'-.' Dashed/dotted line
If you leave out the line value in the fmt parameter, no line will be plott

In [ ]:
Color Reference

'r' Red
'g' Green
'b' Blue
'c' Cyan
'm' Magenta
'y' Yellow
'k' Black
'w' White

In [ ]:
Marker Size
You can use the keyword argument markersize or the shorter version,
ms to set the size of the markers:

In [ ]:
Marker Color
You can use the keyword argument markeredgecolor
or the shorter mec to set the color of the edge of the markers:

You can use the keyword argument markerfacecolor or


the shorter mfc to set the color inside the edge of the markers:

In [1]:
import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o', ms = 20, mfc = 'r',mec="yellow")


plt.show()

In [ ]:
Matplotlib Line
Linestyle
You can use the keyword argument linestyle, or shorter ls, to change the st

In [11]:
import matplotlib.pyplot as plt
import numpy as np
ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, linestyle = 'dotted')


#plt.plot(ypoints, linestyle = 'dashed')
plt.show()

In [ ]:
linestyle can be written as ls.

dotted can be written as :.

dashed can be written as --.

In [7]:
import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

#plt.plot(ypoints, ls = ':')
plt.plot(ypoints, ls = '--')
plt.show()

In [ ]:
Line Styles
You can choose any of these styles:

'solid' (default) '-'


'dotted' ':'
'dashed' '--'
'dashdot' '-.'
'None' '' or ' '

In [ ]:
Line Color
You can use the keyword argument color or the shorter c to set the color of

In [15]:
import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, color = 'r')


#plt.plot(ypoints, c = 'r')
plt.show()

In [ ]:
Line Width
You can use the keyword argument linewidth or the shorter lw to change the

The value is a floating number, in points:

In [16]:
import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, linewidth = '20.5')


plt.show()
In [ ]:
Multiple Lines
You can plot as many lines as you like by simply adding more plt.plot() fun

In [17]:
import matplotlib.pyplot as plt
import numpy as np

y1 = np.array([3, 8, 1, 10])
y2 = np.array([6, 2, 7, 11])

plt.plot(y1)
plt.plot(y2)

plt.show()

In [ ]:
You can also plot many lines by adding the points for the x- and y-axis for
in the same plt.plot() function.

(In the examples above we only specified the points on the y-axis,
meaning that the points on the x-axis got the the default values (0, 1, 2

The x- and y- values come in pairs

In [18]:
import matplotlib.pyplot as plt
import numpy as np

x1 = np.array([0, 1, 2, 3])
y1 = np.array([3, 8, 1, 10])
x2 = np.array([0, 1, 2, 3])
y2 = np.array([6, 2, 7, 11])

plt.plot(x1, y1, x2, y2)


plt.show()

In [ ]:
Matplotlib Labels and Title
Create Labels for a Plot
With Pyplot, you can use the xlabel() and ylabel() functions to set a label

In [20]:
import numpy as np
import matplotlib.pyplot as plt

x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])

plt.plot(x, y)

plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")

plt.show()

In [ ]:
Create a Title for a Plot
With Pyplot, you can use the title() function to set a title for the plot.
In [21]:
import numpy as np
import matplotlib.pyplot as plt

x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])

plt.plot(x, y)

plt.title("Sports Watch Data")


plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")

plt.show()

In [ ]:
Set Font Properties for Title and Labels
You can use the fontdict parameter in xlabel(), ylabel(), and title() to se

In [22]:
import numpy as np
import matplotlib.pyplot as plt

x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])

font1 = {'family':'serif','color':'blue','size':20}
font2 = {'family':'serif','color':'darkred','size':15}

plt.title("Sports Watch Data", fontdict = font1)


plt.xlabel("Average Pulse", fontdict = font2)
plt.ylabel("Calorie Burnage", fontdict = font2)

plt.plot(x, y)
plt.show()
In [ ]:
Position the Title
You can use the loc parameter in title() to position the title.

Legal values are: 'left', 'right', and 'center'. Default value is 'center'

In [23]:
import numpy as np
import matplotlib.pyplot as plt

x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])

plt.title("Sports Watch Data", loc = 'left')


plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")

plt.plot(x, y)
plt.show()

In [ ]:
Add Grid Lines to a Plot
With Pyplot, you can use the grid() function to add grid lines to the plot

In [8]:
import numpy as np
import matplotlib.pyplot as plt

x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])

plt.title("Sports Watch Data")


plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")

plt.plot(x, y)

plt.grid()

plt.show()

In [ ]:
Specify Which Grid Lines to Display
You can use the axis parameter in the grid() function to specify which grid

Legal values are: 'x', 'y', and 'both'. Default value is 'both'.

In [9]:
import numpy as np
import matplotlib.pyplot as plt

x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])

plt.title("Sports Watch Data")


plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")

plt.plot(x, y)

#plt.grid(axis = 'x')
plt.grid(axis = 'x')
#plt.grid(axis = 'both')

plt.show()
In [ ]:
Set Line Properties for the Grid
You can also set the line properties of the grid,
like this: grid(color = 'color', linestyle = 'linestyle', linewidth = numbe

In [10]:
import numpy as np
import matplotlib.pyplot as plt

x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])

plt.title("Sports Watch Data")


plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")

plt.plot(x, y)

plt.grid(color = 'green', linestyle = '--', linewidth = 0.5)

plt.show()

In [ ]:
Display Multiple Plots
With the subplot() function you can draw multiple plots in one figure:
The subplot() Function
The subplot() function takes three arguments that describes the layout of t

The layout is organized in rows and columns, which are represented by the f

The third argument represents the index of the current plot.

In [28]:
import matplotlib.pyplot as plt
import numpy as np

#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(1, 2, 1)
plt.plot(x,y)

#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(1, 2, 2)
plt.plot(x,y)

plt.show()

In [ ]:
if we want a figure with 2 rows an 1 column
(meaning that the two plots will be displayed on top of each other instead

In [29]:
import matplotlib.pyplot as plt
import numpy as np

#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(2, 1, 1)
plt.plot(x,y)

#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])
plt.subplot(2, 1, 2)
plt.plot(x,y)

plt.show()

In [11]:
#Draw 6 plots:

import matplotlib.pyplot as plt


import numpy as np

x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(2, 3, 1)
plt.plot(x,y)

x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(2, 3, 2)
plt.plot(x,y)

x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(2, 3, 3)
plt.plot(x,y)

x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(2, 3, 4)
plt.plot(x,y)

x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(2, 3, 5)
plt.plot(x,y)

x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(2, 3, 6)
plt.plot(x,y)
plt.show()

In [12]:
#2 plots, with titles:
#Add a title for the entire figure:

import matplotlib.pyplot as plt


import numpy as np

#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(1, 2, 1)
plt.plot(x,y)
plt.title("SALES")

#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(1, 2, 2)
plt.plot(x,y)
plt.title("INCOME")

plt.suptitle("MY SHOP")
plt.show()
In [ ]:
Creating Scatter Plots
With Pyplot, you can use the scatter() function to draw a scatter plot.

The scatter() function plots one dot for each observation.


It needs two arrays of the same length, one for the values of the x-axis,
and one for values on the y-axis:

In [30]:
import matplotlib.pyplot as plt
import numpy as np

x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])

plt.scatter(x, y)
plt.show()

In [31]:
#Draw two plots on the same figure:

import matplotlib.pyplot as plt


import numpy as np

#day one, the age and speed of 13 cars:


x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
plt.scatter(x, y)

#day two, the age and speed of 15 cars:


x = np.array([2,2,8,1,15,8,12,9,7,3,11,4,7,14,12])
y = np.array([100,105,84,105,90,99,90,95,94,100,79,112,91,80,85])
plt.scatter(x, y)

plt.show()
In [13]:
import matplotlib.pyplot as plt
import numpy as np

x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
plt.scatter(x, y, color = 'green')

x = np.array([2,2,8,1,15,8,12,9,7,3,11,4,7,14,12])
y = np.array([100,105,84,105,90,99,90,95,94,100,79,112,91,80,85])
plt.scatter(x, y, color = 'red')

plt.show()

In [33]:
#Set your own color of the markers:

import matplotlib.pyplot as plt


import numpy as np

x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
colors = np.array(["red","green","blue","yellow","pink","black","orange","p

plt.scatter(x, y, color=colors)

plt.show()
In [35]:
import matplotlib.pyplot as plt
import numpy as np

x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
sizes = np.array([20,50,100,200,500,1000,60,90,10,300,600,800,75])

plt.scatter(x, y, s=sizes)

plt.show()

In [ ]:
Alpha
You can adjust the transparency of the dots with the alpha argument.

Just like colors, make sure the array for


sizes has the same length as the arrays for the x- and y-axis:

In [36]:
import matplotlib.pyplot as plt
import numpy as np

x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
sizes = np.array([20,50,100,200,500,1000,60,90,10,300,600,800,75])

plt.scatter(x, y, s=sizes, alpha=0.5)

plt.show()
In [ ]:
Creating Bars
With Pyplot, you can use the bar() function to draw bar graphs:

In [14]:
#Draw 4 bars:

import matplotlib.pyplot as plt


import numpy as np

x = np.array(["A", "B", "C", "D"])


y = np.array([3, 8, 1, 10])

plt.bar(x,y)
plt.show()

In [38]:
#The bar() function takes arguments that describes the layout of the bars.

#The categories and their values represented by the first and second argume

x = ["APPLES", "BANANAS"]
y = [400, 350]
plt.bar(x, y)

<BarContainer object of 2 artists>


Out[38]:
In [ ]:
Horizontal Bars
If you want the bars to be displayed horizontally instead of vertically, us

Example
Draw 4 horizontal bars:

In [15]:
import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])


y = np.array([3, 8, 1, 10])

plt.barh(x, y)
plt.show()

In [ ]:
Bar Color
The bar() and barh() takes the keyword argument color to set the color of t

In [39]:
import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])


y = np.array([3, 8, 1, 10])

plt.bar(x, y, color = "red")


plt.show()
In [ ]:
Bar Width
The bar() takes the keyword argument width to set the width of the bars:

Example
Draw 4 very thin bars:

In [40]:
import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])


y = np.array([3, 8, 1, 10])

plt.bar(x, y, width = 0.1)


plt.show()

In [ ]:
Bar Height
The barh() takes the keyword argument height to set the height of the bars

In [41]:
import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])


y = np.array([3, 8, 1, 10])
plt.barh(x, y, height = 0.1)
plt.show()

In [ ]:
Histogram
A histogram is a graph showing frequency distributions.

It is a graph showing the number of observations within each given interval

Example: Say you ask for the height of 250 people, you might end up with a

In [ ]:
Create Histogram
In Matplotlib, we use the hist() function to create histograms.

The hist() function will use an array of numbers to create a histogram,


the array is sent into the function as an argument.

For simplicity we use NumPy to randomly generate an array with 250 values,
where the values will concentrate around 170, and the standard deviation is
Learn more about Normal Data Distribution in our Machine Learning Tutorial

In [16]:
import numpy as np

x = np.random.normal(170, 10, 250)

print(x)

[168.21787054 168.55117909 179.38289562 156.71585737 157.52119981


178.92924535 175.63102729 172.73721841 179.3990827 170.66533857
179.34299109 150.06688566 162.56907876 170.91582289 187.69756607
173.20768606 162.97266156 159.29698385 170.14685928 158.81875047
156.33498998 180.9629091 180.77460258 160.26580309 172.57827635
171.37143588 160.36615302 167.46101094 169.40731479 176.82260698
148.80928867 171.24697762 163.81974245 166.70478002 185.79110729
179.89867447 166.14422374 167.08958805 166.02603778 165.31059308
166.77666468 180.19678949 160.07273057 175.80171094 153.9609993
170.35293342 179.76156864 166.9265059 187.07740928 177.96630357
164.19918964 157.19841428 152.28660363 161.78532649 160.43780027
180.48240535 179.28105532 161.75156013 162.44920049 166.6962223
189.91164515 168.81342593 182.28057919 181.69610419 152.96704404
175.73016339 168.16263156 164.10376032 172.60288593 163.99674039
175.50018679 166.01548407 175.37412186 181.37534525 171.70133303
168.81473057 166.31339086 182.61750102 171.17508226 175.34708903
160.43960876 164.92161772 180.5366355 181.31537641 165.78082196
181.04737405 169.67498924 153.51047226 163.0820889 175.47004049
160.1603814 170.31777753 171.15779904 166.80201042 178.70509699
170.68996644 168.27080425 161.42877591 159.61595077 180.25796195
170.98127969 160.30638074 173.94162897 166.53451027 171.41087727
165.68048773 173.12667812 156.68415184 185.62668548 179.91081865
181.67367224 156.16287672 179.1833414 178.73889688 171.06795416
187.97238536 170.32052174 159.87819672 152.99016578 175.91143365
150.25959501 180.23991612 185.12635729 185.99225959 179.81979398
183.00406064 172.69947244 178.4981673 168.82351836 146.93484169
160.0672855 167.49924653 168.75025026 178.98969591 174.96071963
186.85659967 166.87112798 159.1821003 176.39689771 174.56824474
165.93017395 183.1669683 164.878311 180.91545734 172.24575673
160.39810123 171.60415285 181.95112048 160.73710002 168.94988036
156.01649523 189.86278257 176.35972093 191.20677234 160.61372424
177.79954063 166.63364501 179.43909692 161.77729889 179.33804162
177.59557261 176.54733433 158.72487583 175.97663664 155.52739757
175.87981642 167.33522525 192.13549524 174.9271538 161.18602119
176.84655217 170.85696147 156.64632454 195.83541185 168.54432587
176.89835002 170.66955378 191.76544069 168.26697379 159.51880798
163.98648185 178.42313248 174.45426232 158.06531335 177.30675532
164.39206721 167.43690046 163.44192761 165.84441703 170.68751489
164.49618044 169.02326667 175.91170828 164.71700873 174.1128795
150.56525912 191.71772296 168.00773812 186.16421022 169.13343784
161.80646811 172.15348556 171.26314697 181.18406476 187.41006361
167.12307225 176.36014215 179.20601041 175.90925237 161.97098223
168.07051054 168.05674112 154.35894924 165.03406252 166.02855713
186.44336764 179.11812746 179.8802908 182.44855097 179.59979146
181.01527488 153.38554996 171.75131898 162.58416476 189.25290555
163.98796605 177.98499229 157.4600734 156.3080381 179.92555425
170.25441027 172.59544259 183.22093154 154.79376163 166.97553047
179.55679903 170.36458986 168.72977823 173.67416417 181.99472424
179.25189037 166.47678812 153.05563608 162.92911616 189.59690871
162.1836503 161.63745539 158.81074402 161.02689467 170.87623979]

In [42]:
import matplotlib.pyplot as plt
import numpy as np

x = np.random.normal(170, 10, 250)

plt.hist(x)
plt.show()

In [ ]:
Creating Pie Charts
With Pyplot, you can use the pie() function to draw pie charts:

In [43]:
import matplotlib.pyplot as plt
import numpy as np

y = np.array([35, 25, 25, 15])

plt.pie(y)
plt.show()

In [ ]:
Labels
Add labels to the pie chart with the label parameter.

The label parameter must be an array with one label for each wedge:

In [44]:
import matplotlib.pyplot as plt
import numpy as np

y = np.array([35, 25, 25, 15])


mylabels = ["Apples", "Bananas", "Cherries", "Dates"]

plt.pie(y, labels = mylabels)


plt.show()

In [ ]:
Start Angle
As mentioned the default start angle is at the x-axis,
but you can change the start angle by specifying a startangle parameter.

The startangle parameter is defined with an angle in degrees, default angle

In [17]:
#Start the first wedge at 90 degrees:

import matplotlib.pyplot as plt


import numpy as np

y = np.array([35, 25, 25, 15])


mylabels = ["Apples", "Bananas", "Cherries", "Dates"]

plt.pie(y, labels = mylabels, startangle = 90)


plt.show()

In [ ]:
Explode
Maybe you want one of the wedges to stand out? The explode parameter allows

The explode parameter, if specified, and not None, must be an array with on

Each value represents how far from the center each wedge is displayed:
In [19]: #Pull the "Apples" wedge 0.2 from the center of the pie:

import matplotlib.pyplot as plt


import numpy as np

y = np.array([35, 25, 25, 15])


mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
myexplode = [0.1, 0, 0, 0]

plt.pie(y, labels = mylabels, explode = myexplode)


plt.show()

In [ ]:
Colors
You can set the color of each wedge with the colors parameter.

The colors parameter, if specified, must be an array with one value for eac

In [20]:
import matplotlib.pyplot as plt
import numpy as np

y = np.array([35, 25, 25, 15])


mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
mycolors = ["black", "hotpink", "b", "#4CAF50"]

plt.pie(y, labels = mylabels, colors = mycolors)


plt.show()

In [ ]:

You might also like