0% found this document useful (0 votes)
10 views23 pages

3 Dimensional

Uploaded by

gowri
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)
10 views23 pages

3 Dimensional

Uploaded by

gowri
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/ 23

THREE DIMENSIONAL PLOTTING

AND GEOGRAPICAL DATA


WITH BASE MAP
THREE DIMENSIONAL PLOTTING

➢ The most basic three-dimensional plot is line or collection of scatter plot


created from(x,y,z)triples

➢ Three-dimensional plots can be created using ax.scatter3D and ax.plot3D


functions

➢ 3D plots are the important tool for visualizing the data


THREE-DIMENSIONAL PLOTTING IN
MATPLOTLIB

➢ Matplotlib was initially designed from two-dimensional plotting

➢ Matplotlib was one of the python package and is a simplest way


to plot the graph

➢ Matplotlib is a comprehensive library for creating static,animated


and interactive visualizatons
Example:
import numpy as np
Import matplotlib.pyplot as plt
fig=plt.figure()
ax=plt.axes(projection=‘3d’)

Output:
THREE-DIMENSIONAL POINTS AND LINES

Output:
Example:
ax=plt.axes(projection=‘3d’)
zline=np.linespace(0,15,1000)
xline=np.sin(zline)
yline=np.cos(zline)
ax.scatter3D(xline,yline,zline,’gray’)
zdata=15*np.random.random(100)
xdata=np.sin(zdata)+0.1*np.random.randn(100)
ydata=np.cos(zdata)+0.1*np.random.randn(100)
ax.scatter3D(xdata,ydata,zdata,c=zdata,cmap=‘Greens’);
TYPES OF GRAPH USING MATPLOTLIB LIBRARY

Contour graph

Wireframe
graph

Surface graph
CONTOUR PLOT GRAPH

• The contour graph takes all the input data in two-dimensional


regular grids and z data is evaluated at every point

• We use ax.contour3D function to plot a contour graph

• Contour plots are an excellent way to visualize optimization plots


Example:
def function(x,y):
Output:
return np.sin(np.sqrt(x**2+y**2))
x=np.linespace(-10,10,40)
y=np.linespace(-10,10,40)
X,Y=np.meshgrid(x,y)
Z=function(X,Y)
fig=plt.figure(figsize=(10,8))
ax=plt.axes(projection=‘3d’)
ax.plot_surface(X,Y,Z,cmap=‘cool’,alpha=0.8)
ax.set_title(‘3D Contour Plot of
function(x,y)=\sin(sqrt(x^2+y^2))’,fontsize=14)
ax.set_xlabel(‘x’,fontsize=12)
ax.set_ylabel(‘y’,fontsize=12)
ax.set_zlabel(‘z’,fontsize=12)
Plt.show()
WIREFRAMES PLOT GRAPH

• For plotting wireframes graph we need to use the


plot_wireframe() function from matplotlib library

• It basically takes a grid of values and projects it onto the


specified three-dimensional surface
Example:
Output:
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
def f(x,y):
return np.sin(np.sqrt(x**2+y**2))
x=np.linespace(-1,5,10)
y=np.linespace(-1,5,10)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
Fig=plt.figure()
Ax=plt.axes(projection=‘3d’)
ax.plot_wireframe(X,Y,Z,color=‘green’)
Ax.set_title(‘wireframe geeks for geeks’);
SURFACE PLOT GRAPH

• Surface graph and wireframes graph work on gridded


data

• They take the grid value and plot it on a three-


dimensional surface

• We can use the plot_surface function to plot the surface


plot
Ouput:
Example:
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
x=np.outer(np.linespace(-2,2,10),np.ones(10))
y=x.copy().T
z=np.cos(x**2+y**3)
fig=plt.figure()
ax=plt.axes(projections=‘3d’)
ax=plot_surface(x,y,z,cmap=‘viridis’,\edgecolor=‘green’)
ax.set_title(‘surface plot geeks for geeks’)
plt.show()
GEOGRAPHIC DATA WITH BASE MAP

➢Geographic data is one of the common type of visualization in data science

➢Matplotlib is main tool for this type of visualization is basemap


toolkit,which is under mpl_toolkits namespace
INSTALLATION OF BASEMAP:
➢If you’re using conda you can type this and the package will be downloaded
$ conda install basemap
Example:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
plt.figure(figure=(8,8))
m=Basemap(projection=‘ortho’,resolution=None,lat_0=50,lon_0=-100)
m=bluemarble(scale=0.5);

Output:
MAP PROJECTIONS

• Map projections are representations of a sphere(earth)in


two-dimensions
• A Mathematical transformation is required in order to
convert Latitude and Longitude
• A Coordinate system is usually defined by map
projections
CYLINDRICAL PROJECTIONS

➢The simplest form of map projections are cylindrical


projections,in which longitude and latitude are mapped

➢This projections is used in world maps and regions


bordering the equator
Example:
fig=plt.figure(figure=(8,6),edgecolor=‘w’)
basemap(projection=‘cyl’,resolution=None,llcrnrlat=-90,urcrnrlat=90,llcrnrlon=-
180,urcrnrlon=180,)
draw_map(m)

Output:
PSEUDO-CYLINDRICAL PROJECTIONS

• Pseudo-cylindrical projections relax the requirement that meridians


remain vertical

• This can give better properties near the poles of projections

• Mollweide projection (projection=‘moll’)is one common example


Example:
fig =plt.figure(figure(figsize=(8,6),edgecolor=‘w’)
m=Basemap(projection=‘moll’,resolution=None,lat_0=0,lon_0=0)
draw_map(m)

Output:
PERSPECTIVE PROJECTIONS

➢Perspective projections are constructed using a particular


choice of perspective point,similar to earth from particular
point

➢One common eg is orthographic (projection=‘ortho’)

➢It shows one side of globe which it can show only half side at a
time
Example:

fig=plt.figure(figsize=(8,8))
m=Basemap(projection=‘ortho’,resolution=None,lat_0=50,lon_0=0)
draw_map(m)

Output:
CONIC PROJECTIONS

• A conic projections projects the map onto a single


cone,which is unrolled

• One common eg is Lambert Conformal Conic


projection(projection=‘lcc’)

• This can lead to very good local properties,but regions far


from focus point may become distorted
Example:
fig=plt.figure(figsize=(8,8))
m=Basemap(projection=‘lcc’,resolution=None,lon_0=0,lat_0=50,lat_1=45,lat_2=
55,width=1.6E7,height=1.2E7)
draw_map(m)

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy