0% found this document useful (0 votes)
2 views8 pages

Matplotlib Part1

The document provides an overview of using Matplotlib for data visualization in Python, highlighting its simplicity and capabilities such as exporting images and controlling graphic elements. It includes code examples demonstrating basic plotting, subplots, labeling, and adding text with LaTeX formatting. The document emphasizes the importance of axes and figure objects in creating effective visual representations of data.

Uploaded by

db7646461
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Matplotlib Part1

The document provides an overview of using Matplotlib for data visualization in Python, highlighting its simplicity and capabilities such as exporting images and controlling graphic elements. It includes code examples demonstrating basic plotting, subplots, labeling, and adding text with LaTeX formatting. The document emphasizes the importance of axes and figure objects in creating effective visual representations of data.

Uploaded by

db7646461
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

#matplotlib, seaborn

# Extremely simple to use


#Latex also
##export into images like png etc, jpeg
#Greater control over graphic elements

!pip install matplotlib

Requirement already satisfied: matplotlib in /usr/local/lib/python3.12/dist-packages (3.10.0)


Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib) (1.3.3)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.12/dist-packages (from matplotlib) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib) (4.59.2)
Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib) (1.4.9)
Requirement already satisfied: numpy>=1.23 in /usr/local/lib/python3.12/dist-packages (from matplotlib) (2.0.2)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib) (25.0)
Requirement already satisfied: pillow>=8 in /usr/local/lib/python3.12/dist-packages (from matplotlib) (11.3.0)
Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib) (3.2.3)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.12/dist-packages (from matplotlib) (2.9.0.post0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.7->matplotlib) (1.17.0)

# Figure : Object entire graph


#Axes : plot or chart
#Axis : numerical values that are represented in , manges the ticks,

import matplotlib.pyplot as plt


import numpy as np

plt.plot([1,2,3,4])

[<matplotlib.lines.Line2D at 0x7fe8ebe9b320>]

plt.plot([1,2,3,4],[1,4,9,16])
[<matplotlib.lines.Line2D at 0x7fe8eac88500>]

plt.plot([1,2,3,4],[1,4,9,16],'ro')

[<matplotlib.lines.Line2D at 0x7fe8eb1c4fe0>]

#xmin, xmax, y_min, y_max


plt.axis([0,6,0,20])
plt.title('Square Numbers')
plt.xlabel('Value')
plt.ylabel('Square of Value')
plt.plot([1,2,3,4],[1,4,9,16],'ro')
[<matplotlib.lines.Line2D at 0x7fe8eb258b90>]

import math
t = np.arange(0,2.5,0.1)
y1 = np.sin(math.pi*t)
y2 = np.sin(math.pi*t+math.pi/2)
y3 = np.sin(math.pi*t-math.pi/2)
plt.plot(t,y1,'b*',t,y2,'g^',t,y3,'ys')

[<matplotlib.lines.Line2D at 0x7fe8e889a0f0>,
<matplotlib.lines.Line2D at 0x7fe8e86d9d00>,
<matplotlib.lines.Line2D at 0x7fe8e86d9f70>]

t = np.arange(0,2.5,0.1)
y1 = np.sin(math.pi*t)
y2 = np.sin(math.pi*t+math.pi/2)
y3 = np.sin(math.pi*t-math.pi/2)
plt.plot(t,y1,'b--',t,y2,'g',t,y3,'r--')

[<matplotlib.lines.Line2D at 0x7fe8e86c4e60>,
<matplotlib.lines.Line2D at 0x7fe8e86c4cb0>,
<matplotlib.lines.Line2D at 0x7fe8e86c5070>]

#sub plots
t = np.arange(0,5,0.1)
y1 = np.sin(2*np.pi*t)
y2 = np.sin(4*np.pi*t)
plt.subplot(2,1,1)
plt.plot(t,y1,'b--')
plt.subplot(2,1,2)
plt.plot(t,y2,'r--')

[<matplotlib.lines.Line2D at 0x7fe8eaf785f0>]
t = np.arange(0,5,0.1)
y1 = np.sin(2*np.pi*t)
y2 = np.sin(4*np.pi*t)
plt.subplot(1,2,1)
plt.plot(t,y1,'r--')
plt.subplot(1,2,2)
plt.plot(t,y2,'b--')

[<matplotlib.lines.Line2D at 0x7fe8eab003e0>]

#list the colors in the plot of matplotlib


# Adding text to the figure
plt.axis([0,5,0,20])
plt.title('Square Numbers')
plt.xlabel('Value')
plt.ylabel('Square of Value')
plt.plot([1,2,3,4],[1,4,9,16],'ro')
[<matplotlib.lines.Line2D at 0x7fe8eaf21010>]

# write lables 1,2,3,4 at each point in the above graph


plt.axis([0,5,0,20])
plt.title('Square Numbers')
plt.xlabel('Value')
plt.ylabel('Square of Value')
plt.plot([1,2,3,4],[1,4,9,16],'ro')
plt.text(1,1.5,'First')
plt.text(2,4.5,'Second')
plt.text(3,9.5,'Third')
plt.text(4,16.5,'Fourth')
#to print r'$y=x^2' as latex
plt.text(1.1,12, r'$y=x^2', fontsize = 20,
bbox={'facecolor':'yellow','alpha':0.5})
Text(1.1, 12, '$y=x^2')

# write lables 1,2,3,4 at each point in the above graph


plt.axis([0,5,0,20])
plt.title('Square Numbers')
plt.xlabel('Value')
plt.ylabel('Square of Value')
plt.plot([1,2,3,4],[1,4,9,16],'ro')
plt.text(1,1.5,'First')
plt.text(2,4.5,'Second')
plt.text(3,9.5,'Third')
plt.text(4,16.5,'Fourth')
plt.grid(True)
#to print r'$y=x^2' as latex
plt.text(1.1,12, r'$y=x^2', fontsize = 20,
bbox={'facecolor':'yellow','alpha':0.5})
Text(1.1, 12, '$y=x^2')

# write lables 1,2,3,4 at each point in the above graph


plt.axis([0,5,0,20])
plt.title('Square Numbers')
plt.xlabel('Value')
plt.ylabel('Square of Value')
plt.plot([1,2,3,4],[1,4,9,16],'ro')
plt.text(1,1.5,'First')
plt.text(2,4.5,'Second')
plt.text(3,9.5,'Third')
plt.text(4,16.5,'Fourth')
plt.legend(['First series'],loc = 'upper left')
plt.grid(True)
#to print r'$y=x^2' as latex
plt.text(1.1,12, r'$y=x^2', fontsize = 20,
bbox={'facecolor':'yellow' 'alpha':0 5})

You might also like