Top Posts
Types of JDBC drivers
C++ Program to implements Constructor Overloading
C++ Program to implements Constructor
C++ Program to calculate the area using classes
C++ Class Program to Store and Display Employee...
Operator Overloading of Decrement — Operator
Postfix Increment ++ Operator Overloading
Prefix Increment ++ operator overloading with return type
Prefix ++ Increment Operator Overloading with no return...
JDBC Architecture
TECHARGE
  • HOME
  • BLOGS
  • TUTORIALS
    • ALL TUTORIALS
    • PROGRAMMING TUTORIALS
      • JAVA TUTORIALS
      • C++ TUTORIAL
      • C PROGRAMMING TUTORIALS
      • PYTHON TUTORIAL
      • KNOWLEDGE MANAGEMENT TUTORIALS
      • DATA STRUCTURE AND ALGORITHM TUTORIALS
      • PROGRAMMING EXAMPLES
        • CPP EXAMPLES
        • JAVA EXAMPLES
        • C++ GRAPHICS PROGRAM
    • PROJECTS
      • PYTHON PROJECTS
      • SWIFT PROJECT
    • PPROGRAMMING QUIZ
    • DBMS TUTORIALS
    • COMPUTER NETWORK TUTORIALS
    • COMPUTER NETWORK SECURITY TUTORIALS
    • E COMMERCE TUTORIALS 
    • AWS TUTORIAL
    • INTERNET OF THINGS
    • CHEATSHEET
  • MORE
    • JOBS AND INTERNSHIPS
    • INTERVIEW PREPARATION
    • TECH BOOK
    • TECH NEWS
    • INSTAGRAM GALLERY
    • UNIVERSITY PAPERS
    • MNC TWEETS
    • THINKECO INITIATIVES
    • WEB STORIES
    • CONTACT US
  • WRITE +
  • ABOUT US
Matplotlib Library

Python: Plots, Images, Contour and Pseudocolor in Matplotlib

by Prateek Kashyap December 1, 2022
written by Prateek Kashyap 0 comment
Python: Plots, Images, Contour and Pseudocolor in Matplotlib
Python: Plots, Images, Contour and Pseudocolor in Matplotlib

Table of Contents

  • Line Plot in Matplotlib
      • Output:
  • Multiple subplots in one figure in Matplotlib
      • Output:
  • Images in Matplotlib
      • Output:
  • Contouring and pseudocolor in Matplotlib
      • Output:

In this article, you’ll learn about Line Plot in Matplotlib, Multiple subplots in one figure in Matplotlib, Contouring and pseudocolor in Matplotlib, Images in Matplotlib.

Line Plot in Matplotlib

Here’s how to create a Line plot with text labels using plot().

import matplotlib 
import matplotlib.pyplot as plt 
import numpy as np 

# Data for plotting 
t = np.arange(0.0, 2.0, 0.01) 
s = 1 + np.sin(2*np.pi*t) 

fig, ax = plt.subplots() 
ax.plot(t, s)
 
ax. set (xlabel='time (s)',ylabel=' voltage(mV)' 
              title='About as simple as it gets, folks' ) 
ax.grid() 

fig. savefig("test.png") 
plt. show( )

Output:

Line Plot in Matplotlib
Line Plot in Matplotlib

Multiple subplots in one figure in Matplotlib

Multiple axes (i.e. subplots) are created with the subplot() function:

import numpy as np 
import matplotlib.pyplot as plt 
x1 = np.linspace(0.0, 5.0) 
x2 = np.linspace(0.0, 2.0)
 
y1 = np.cos(2 * np.pi * x1) * np.exp(-x1) 
y2 = np.cos(2 * np.pi * x2) 

fig, (ax1, ax2) = plt.subplots(2, 1) 
fig.suptitle('A tale of 2 subplots') 

ax1.plot(x1, y1, 'o-') 
ax1.set_ylabel('Damped oscillation') 

ax2.plot(x2, y2, '.-') 
ax2.set_xlabel('time (s)') 
ax2.set_ylabel('Undamped') 

plt.show() 

Output:

Multiple subplots in one figure in Matplotlib
Multiple subplots in one figure in Matplotlib

Images in Matplotlib

Using the imshow() function, Matplotlib can display images (assuming equally spaced horizontal dimensions).

import numpy as np 
import matplotlib.cm as cm 
import matplotlib.pyplot as plt 
import matplotlib.cbook as cbook 
from matplotlib.path import Path 
from matplotlib.patches import PathPatch 
# A sample image 
w, h= 512, 512 

with cbook.get_sample_data('ct.raw.gz') as datafile: 
         s=datafile.read() 

A = np.frombuffer(s, np.uint16).astype(float).reshape((w, h)) 
A /= A.max()
 
fig, ax = plt.subplots() 
extent = (0, 25, 0, 25) 
im = ax.imshow(A, cmap=plt.cm.hot, origin='upper', extent=extent) 

markers=[(15.9,14.5),(16.8,15)]
x, y = zip(*markers) 
ax.plot(x, y,'o')
 
ax.set_title('CT density')
 
plt.show() 

Output:

Images in Matplotlib
Images in Matplotlib

Contouring and pseudocolor in Matplotlib

A colored representation of a two-dimensional array can be done by the pcolormesh() function. Even if there is the uneven spacing between the horizontal dimensions. The contour() is another way for the same data to be represented:

import matplotlib 
import matplotlib.pyplot as plt 
from matplotlib.colors import BoundaryNorm
from matplotlib.ticker import MaxNLocator 
import numpy as np 
np.random.seed(19680801) 
Z = np.random.rand(6, 10) 
x = np.arange(-0.5, 10, 1)   # ten = 11 
y = np.arange(4.5, 11, 1)  # ten = 7
 
fig, ax = plt.subplots() 
ax.pcolormesh(x, y, Z)
plt.show()

Output:

Contouring and pseudocolor in Matplotlib
Contouring and pseudocolor in Matplotlib

Hope you enjoyed this article on Plots, Images, Contour and Pseudocolor in Matplotlib, Happy Programming 🙂

Contouring in pythonimage in pythonline graphlinear graphPseudocolor in pythonStreamplot in pythonsubplot matplotlibsubplotsThree-dimensional Plotting in python
Share 3 FacebookTwitterLinkedinRedditWhatsappTelegramEmail
Prateek Kashyap

Studies Computer Science Engineering at Bundelkhand institute of engineering and technology, Jhansi. love programming, specialization in C, C++ and Python programming languages.

previous post
Modes of Transmission in Network
next post
What is Network ? Network Criteria

You may also like

Python | GUI Widgets, Date Tick labels, Polar Plots, and XKCD-style sketch...

Python : PathPatch ,3D plotting & StreamPlot in Mathplotlib

Python | Ellipse, Pie Charts, Tables and Scatter Plot in Matplotlib

Python | Pyplot in Matplotlib Tutorial

Python | Introduction to Matplotlib Library Tutorial

Python | Decay , Bayes Update ,Double Pendulum problem and Oscilloscope in...

PYTHON Tutorial

  • Online Python Compiler
  • Getting Started with Python
  • String in Python
  • Python Data Types
  • Python Operators
  • Python Keywords and Identifiers
  • Python Input, Output, and Import
  • Python if else
  • Python List
  • Python Dictionary
  • Python Libraries
  • Matplotib Tutorial
    • Python | Introduction to Matplotlib Library Tutorial
    • Python | Pyplot in Matplotlib Tutorial
    • Python | Ellipse, Pie Charts, Tables and Scatter Plot in Matplotlib
    • Python : PathPatch ,3D plotting & StreamPlot in Mathplotlib
    • Python: Plots, Images, Contour and Pseudocolor in Matplotlib

Keep in touch

Facebook Twitter Instagram Pinterest

Recent Posts

  • Types of JDBC drivers

    December 28, 2022
  • C++ Program to implements Constructor Overloading

    December 27, 2022
  • C++ Program to implements Constructor

    December 27, 2022
  • C++ Program to calculate the area using classes

    December 26, 2022

EDUCATIONAL

  • Difference between Google Cloud Platform, AWS and Azure

  • Google Apps You Should Be Using in 2022

  • Top Sites From Where You Can Learn

  • PyScript: Python in the Browser

  • Best Fake Email Generators (Free Temporary Email Address)

  • How to Find Out Who Owns a Domain Name

  • Mobile phone brands by country of origin

  • How to start a new YouTube Channel in 2022

  • Best way to use google search you won’t believe exist

  • 10 mostly asked questions related to WhatsApp

CHEATSHEET

  • Git and Github 2022 Cheat Sheet

  • ReactJs Cheatsheet

  • Linux Commands Cheat Sheet

  • C Programming language Cheatsheet

  • Scala Cheatsheet

  • MySQL Cheatsheet

  • Javascript Cheatsheet

PROJECTS

  • Print emojis using python without any module

  • Country Date and Time using Python

  • Covid-19 Tracker Application Using Python

  • Python | GUI Calendar using Tkinter

  • Python: Shutdown Computer with Voice

  • Python GUI Calculator using Tkinter

  • Convert an Image to ASCII art using Python

  • Python YouTube Downloader with Pytube

  • Tic-Tac-Toe using Python

  • Draw Indian Flag using Python

  • Drawing Pikachu with the Python turtle library

  • Word Dictionary using Tkinter

TECH NEWS

  • 5+ Best Humanoid Robots In The World

  • Reliance Jio launches streaming platform JioGamesWatch

  • Microsoft Teams down for thousands of users

  • Carbon: Google programming language as a C++ successor

JOBS AND INTERNSHIPS

  • Accenture Off Campus Hiring Drive | Associate Job | Program Project Management | 2019-2022 Batch| Apply Now

    September 1, 2022

@2019-21 - All Right Reserved. Designed and Developed by Techarge

TECHARGE
  • HOME
  • BLOGS
  • TUTORIALS
    • ALL TUTORIALS
    • PROGRAMMING TUTORIALS
      • JAVA TUTORIALS
      • C++ TUTORIAL
      • C PROGRAMMING TUTORIALS
      • PYTHON TUTORIAL
      • KNOWLEDGE MANAGEMENT TUTORIALS
      • DATA STRUCTURE AND ALGORITHM TUTORIALS
      • PROGRAMMING EXAMPLES
        • CPP EXAMPLES
        • JAVA EXAMPLES
        • C++ GRAPHICS PROGRAM
    • PROJECTS
      • PYTHON PROJECTS
      • SWIFT PROJECT
    • PPROGRAMMING QUIZ
    • DBMS TUTORIALS
    • COMPUTER NETWORK TUTORIALS
    • COMPUTER NETWORK SECURITY TUTORIALS
    • E COMMERCE TUTORIALS 
    • AWS TUTORIAL
    • INTERNET OF THINGS
    • CHEATSHEET
  • MORE
    • JOBS AND INTERNSHIPS
    • INTERVIEW PREPARATION
    • TECH BOOK
    • TECH NEWS
    • INSTAGRAM GALLERY
    • UNIVERSITY PAPERS
    • MNC TWEETS
    • THINKECO INITIATIVES
    • WEB STORIES
    • CONTACT US
  • WRITE +
  • ABOUT US