0% found this document useful (0 votes)
3 views5 pages

Matplotlib Guide

The document provides a comprehensive guide on setting up and creating basic plots using Matplotlib, including line plots, histograms, pie charts, and subplots. It includes a syntax reference for various plotting functions and customization options, as well as data manipulation techniques using NumPy and Pandas. The document serves as a practical resource for users looking to visualize data effectively.

Uploaded by

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

Matplotlib Guide

The document provides a comprehensive guide on setting up and creating basic plots using Matplotlib, including line plots, histograms, pie charts, and subplots. It includes a syntax reference for various plotting functions and customization options, as well as data manipulation techniques using NumPy and Pandas. The document serves as a practical resource for users looking to visualize data effectively.

Uploaded by

abenav2612
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Setup and Basic Line Plot 📈

Installation & Imports

Creating Your First Plot

[Link]
Histogram

Pie Chart

Subplots (2x2 Grid)

In Matplotlib, a subplot refers to an individual plot or set of axes within a larger figure. When you
want to display multiple plots arranged in a grid or specific layout within a single window, you use
subplots.
3. Matplotlib Function Syntax Reference

A. Plotting Functions

FUNCTION PURPOSE SYNTAX

[Link]() Creates a line chart. [Link](x_coords, y_coords, **kwargs)

[Link]() Creates a vertical bar chart. [Link](x_categories, y_values, **kwargs)

[Link]() Creates a horizontal bar [Link](y_categories, x_values, **kwargs)


chart.

[Link]( Creates a scatter plot. [Link](x_coords, y_coords, **kwargs)


)

[Link]() Creates a pie chart. [Link](values, **kwargs)

[Link]() Creates a histogram. [Link](data_array, **kwargs)

[Link]() Displays the figure. [Link]()

B. Labels and Aesthetics Functions

FUNCTION PURPOSE SYNTAX

[Link]() Sets the main title. [Link]('Title Text', **kwargs)

[Link]() Sets the X-axis label. [Link]('X-axis Label', **kwargs)


[Link]() Sets the Y-axis label. [Link]('Y-axis Label', **kwargs)

[Link]() Forces ticks on the X-axis. [Link](list_or_array_of_values)

PLT.TICK_PARAMS() Customizes tick mark appearance. plt.tick_params(axis='both', **kwargs)

[Link]() Shows the legend. [Link]()

[Link]() Adds a grid. [Link](axis='both', **kwargs)

PLT.TIGHT_LAYOUT() Adjusts layout to prevent overlap. plt.tight_layout()

4. Customization Keywords and Data Tool Syntax

A. Common Plot Customization Arguments (**kwargs)

ARGUMENT DESCRIPTION CHART USAGE EXAMPLE


TYPE

COLOR Sets the color of the line, bar, or marker. All color='#1f77b4'

LINESTYLE Style of the line ('dashed', 'dotted', plot linestyle='dashed'


'solid').

LINEWIDTH Thickness of the line. plot linewidth=4

MARKER Style of the data point marker (e.g., '.', plot marker='o'
'o').

MARKERSIZE Size of the marker. plot markersize=30


(MS)

ALPHA Sets transparency (0.0 to 1.0). scatter, alpha=0.5


hist

LABEL Sets the label for an element, used by plot, label='Class A'
[Link](). scatter

BINS Number of intervals (bins) for the data. hist bins=10

AUTOPCT Format string for displaying percentages. pie autopct='%1.1f%%'

EXPLODE A list of values to displace slices. pie explode=[0, 0, 0.1,


0]

B. NumPy (np) and Pandas (pd) Syntax

Libr Function Purpose Syntax


ary
NumPy [Link]() Converts a [Link](list)
Python list into a
NumPy array.

NumPy [Link]() Generates [Link](loc=mean, scale=std_dev,


random,
normally size=count)
distributed
numbers.

NumPy [Link]() Limits array [Link](array, min_val, max_val)


values to be
within a
min/max range.

Pandas pd.read_csv() Reads a CSV file df = pd.read_csv('[Link]')


into a
DataFrame.

Pandas .value_counts() Counts unique df['Column'].value_counts(ascending=True)


values in a
column (Series).

You might also like