Program Syntax DVP
Program Syntax DVP
A bar plot or bar chart is a graph that represents the category of data with
rectangular bars with lengths and heights that is proportional to the values
which they represent.
The bar plots can be plotted horizontally or vertically. A bar chart describes the
comparisons between the discrete categories. One of the axis of the plot
represents the specific categories being compared, while the other axis
represents the measured values corresponding to those categories
The function creates a bar plot bounded with a rectangle depending on the given
parameters. Following is a simple example of the bar plot, which represents the
number of students enrolled in different courses of an institute.
Syntax:
matplotlib.pyplot.scatter (x_axis_data, y_axis_data, s=None,
c=None, marker=None, cmap=None,
vmin=None, vmax=None, alpha=None,
linewidths=None, edgecolors=None)
Parameters:
x_axis_data: An array containing data for the x-axis.matplotlib
s: Marker size, which can be a scalar or an array of size equal to the size of x or
y.
c: Color of the sequence of colors for markers.
marker: Marker style.
cmap: Colormap name.
linewidths: Width of the marker border.
edgecolor: Marker border color.
alpha: Blending value, ranging between 0 (transparent) and 1 (opaque).
Except for x_axis_data and y_axis_data, all other parameters are optional, with
their default values set to None. The scatter plot examples below demonstrate
the versatility of the scatter() method by showcasing various combinations of
these optional parameters.
Matplotlib.pyplot.scatter() in Python
There are various ways of creating plots using matplotlib.pyplot.scatter() in
Python, There are some examples that illustrate the
matplotlib. pyplot.scatter() function in matplotlib.plot:
1) Basic Scatter Plot
2) Scatter Plot With Multiple Datasets
3) Bubble Chart Plot
4) Customized Scatter Plot
5A) Python program to Demonstrate how to Draw a Histogram Plot using
Matplotlib
Attribute Parameter
default is “bar”
5B) Python program to Demonstrate how to Draw a Pie Chart using Matplotlib.
Plot a pie chart in Python using Matplotlib :
A Pie Chart is a circular statistical plot that can display only one series of data.
The area of the chart is the total percentage of the given data.
The area of slices of the pie represents the percentage of the parts of the data.
The slices of pie are called wedges. The area of the wedge is determined by the
length of the arc of the wedge.
The area of a wedge represents the relative percentage of that part with respect
to whole data. Pie charts are commonly used in business presentations like
sales, operations, survey results, resources, etc as they provide a quick
summary.
Creating Pie Chart:
Matplotlib API has pie() function in its pyplot module which create a pie chart
representing the data in an array.
Syntax: matplotlib.pyplot.pie(data, explode=None, labels=None,
colors=None, autopct=None, shadow=False)
Parameters:
data represents the array of data values to be plotted, the fractional area of each
slice is represented by data/sum(data). If sum(data)<1, then the data values
returns the fractional area directly, thus resulting pie will have empty wedge of
size 1-sum(data).
labels is a list of sequence of strings which sets the label of each wedge.
color attribute is used to provide color to the wedges.
autopct is a string used to label the wedge with their numerical value.
shadow is used to create shadow of wedge.
x and y co-ordinates are marked using circular markers of size 12 and green
color line with — style of width 2
plot.xlabel(‘X-axis’): names x-axis
plot.ylabel(‘Y-axis’): names y-axis
plot(x, y, label = ‘Sample line ‘): plotted Sample Line will be displayed as a
legend
What is Pyplot in Matplotlib?
Pyplot is a Matplotlib module that provides a MATLAB-like interface.
Matplotlib is designed to be as usable as MATLAB, with the ability to use
Python and the advantage of being free and open-source.
Each pyplot function makes some changes to a figure: e.g., creates a figure,
creates a plotting area in a figure, plots some lines in a plotting area, decorates
the plot with labels, etc.
The various plots we can utilize using Pyplot are Line
Plot, Histogram, Scatter, 3D Plot, Image, Contour, and Polar
6B) Python program to illustrate liner plotting with line formatting using
Matplotlib.
Matplotlib Simple Line Plot
A simple line chart is generated using NumPy to define data values.
The x-values are evenly spaced points, and the y-values are calculated as twice
the corresponding x-values.
7) Write a Python program which explains uses of customizing
seaborn plots with Aesthetic functions.
In this tutorial, we will learn about Python Seaborn from basics to advance
using a huge dataset of seaborn basics, concepts, and different graphs that can
be plotted.
1. Data Generation:
The script uses numpy to generate a series of sine wave plots.
2. Seaborn Integration:
seaborn is imported and configured with a default theme
(set_theme).
The context is set to “notebook” with customized font scaling and
line width (set_context).
3. Customized Aesthetics:
The sinplot function generates multiple sine wave plots with
varying frequencies and amplitudes.
4. Title and Display:
The script adds a title to the plot, ‘Seaborn Plots with Aesthetic
Functions.’
The show function is called to display the generated plots.
a) Write a Python program for plotting different types of plots using Bokeh.
provided Python script demonstrates the use of the Bokeh library to create
interactive data visualizations with multiple plots. Here’s a concise overview:
1. Data Generation:
The script generates example data ( x and y) using NumPy to represent
sine waves.
2. Interactive Tools:
Bokeh’s interactive tools ( TOOLS) are enabled for features like pan,
zoom, reset, and save.
3. Multiple Plots:
Two separate plots ( p1 and p2) are created with different visualizations,
including circles, lines, and markers.
4. Legend and Titles:
Legends are added to distinguish between different elements in the
plots.
Titles are provided for each plot.
5. Grid Layout:
The gridplot function is used to arrange the plots in a grid layout.
6. Interactive Display:
The show function is called to display the grid layout, enabling
interactive exploration.
Another Example
import plotly.express as px
df = px.data.gapminder().query("continent=='Asia'")
fig = px.line_3d(df, x="gdpPercap", y="pop", z="year", color='country', title='Economic Evolution of Asian
Countries Over Time')
fig.show()
In this Python program, we leverage the power of Plotly Express to visualize the
economic evolution of Asian countries over time. The dataset used is Gapminder, a
comprehensive collection of global development indicators. The focus is specifically
on the Asian continent.
1. Import Libraries:
We start by importing the necessary libraries, including plotly.express for
interactive visualizations.
2. Data Loading:
We load the Gapminder dataset and filter it to include only Asian countries.
3. 3D Line Plot:
The key visualization is a 3D line plot created using px.line_3d .
The x-axis represents the GDP per capita ( gdpPercap ), the y-axis represents
the population ( pop), and the z-axis represents the year ( year).
Each line corresponds to a different country, differentiated by color.
4. Interactive Exploration:
The resulting plot is interactive, allowing users to zoom, pan, and hover over
data points to explore specific details.
Users can observe how GDP per capita and population have changed over the years
for various Asian countries. The color-coded lines help distinguish between different
nations.
Output
CUR_DLR_INR.csv
CUR_DLR_INR Download
The provided Python script showcases the use of the Plotly Express library to create
an interactive line plot depicting the exchange rate between the US Dollar and the
Indian Rupee over time. Here’s a concise overview:
1. Data Import:
The script uses the Pandas library to read currency conversion data from a
CSV file (‘CUR_DLR_INR.csv’). You can download the csv file given above.
2. Plotly Express:
Plotly Express ( px) is employed to create an interactive line plot with the
exchange rate data.
3. Line Plot:
The line function from Plotly Express is used to generate a line plot.
The x-axis represents dates (‘DATE’), and the y-axis represents exchange rates
(‘RATE’).
4. Title:
The plot is given a title, ‘Dollar vs Rupee,’ for context.
5. Interactive Display:
The show method is called on the figure ( fig) to display the interactive plot.
This script provides a quick and effective demonstration of using Plotly Express to
visualize time-series data, making it suitable for readers interested in creating
interactive and visually appealing line plots for financial or currency-related datasets.
10B) write a python program for creating maps using Plotly Libraries .
Choropleth maps