Zeta - Updated - Matplotlib - Ipynb - Colab
Zeta - Updated - Matplotlib - Ipynb - Colab
ipynb - Colab
plt.plot(x, y)
plt.show()
# Default X-Points
#import matplotlib.pyplot as plt
import numpy as np
plt.plot(y)
plt.show()
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 1/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
To plot only the markers, you can use shortcut string notation parameter 'o', which means 'rings'
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
keyboard_arrow_down Markers
You can use the keyword argument marker to emphasize each point with a specified marker:
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 2/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
Marker Size
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
Marker Color shorter mec to set the color of the edge of the markers:
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 3/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 4/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
Dotted plot
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
Line Color
You can use the keyword argument color or the shorter c to set the color of the line
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
plt.plot(x,y,marker = '*',ms = 20, mec= "yellow", mfc = 'r', linestyle = 'dotted', color="brown")
plt.show()
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 5/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
Line Width
You can use the keyword argument linewidth or the shorter lw to change the width of the line.
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
plt.plot(x,y,marker = '*',ms = 20, mec= "yellow", mfc = 'r', linestyle = 'dotted', color="magenta", linewidth = '2.5')
plt.show()
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
plt.plot(x,marker = '*',ms = 20, mec= "yellow", mfc = 'r', linestyle = 'dotted', color="magenta", linewidth = '2.5')
plt.plot(y,marker = '*',ms = 20, mec= "yellow", mfc = 'r', linestyle = 'dotted', color="green", linewidth = '2.5')
plt.show()
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 6/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
#Draw two lines by specifiyng the x- and y-point values for both lines:
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])
With Pyplot, you can use the xlabel() and ylabel() functions
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
plt.plot(x,y,marker = '*',ms = 20, mec= "yellow", mfc = 'r', linestyle = 'dotted', color="magenta", linewidth = '2.0')
plt.xlabel("Demand")
plt.ylabel("Supply")
plt.show()
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 7/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
With Pyplot, you can use the title() function to set a title for the plot.
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
plt.plot(x,y,marker = '*',ms = 20, mec= "yellow", mfc = 'r', linestyle = 'dotted', color="magenta", linewidth = '2.0')
plt.title("Demand-Supply Management")
plt.xlabel("Demand")
plt.ylabel("Supply")
plt.show()
You can use the fontdict parameter in xlabel(), ylabel(), and title() to set font properties for the title and labels.
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 8/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
font1 = {'family':'serif','color':'blue','size':18}
font2 = {'family':'serif','color':'darkred','size':18}
plt.plot(x,y,marker = '*',ms = 20, mec= "yellow", mfc = 'r', linestyle = 'dotted', color="magenta", linewidth = '2.0')
plt.show()
With Pyplot, you can use the grid() function to add grid lines to the plot.
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1, 2, 6, 8, 10])
y = np.array([3, 8, 1, 10, 23])
font1 = {'family':'serif','color':'blue','size':18}
font2 = {'family':'serif','color':'darkred','size':18}
plt.plot(x,y,marker = '*',ms = 20, mec= "yellow", mfc = 'r', linestyle = 'dotted', color="magenta", linewidth = '2.0')
plt.grid()
plt.show()
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 9/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
With the subplots() function you can draw multiple plots in one figure:
#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()
Matplotlib Bars
Creating Bars With Pyplot, you can use the bar() function to draw bar graphs:
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 10/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
import matplotlib.pyplot as plt
import numpy as np
plt.bar(x,y)
plt.show()
Matplotlib Histograms
Example: Say you ask for the height of 250 people, you might end up with a histogram like this:
plt.hist(x)
plt.show()
With Pyplot, you can use the pie() function to draw pie charts:
plt.pie(x)
plt.show()
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 11/12
8/19/24, 9:21 AM zeta_Updated_matplotlib.ipynb - Colab
Legend
To add a list of explanation for each wedge, use the legend() function:
https://colab.research.google.com/drive/1M6IBhhFq-ZZh24mfaACI_dwuVzLrkEby#printMode=true 12/12