Top Posts
Python Operators
Host IT Smart – An Honest Review about...
Life cycle of a thread in Java
Multithreading in Java
Python Keywords and Identifiers
Java Database Connections | JDBC Tutorial
CSJMU BCA 1 SEM QUESTION PAPERS
C++ Structure
Data Transmission in Network
Computer Network and its Component
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
    • UNIVERSITY PAPERS
    • MNC TWEETS
    • THINKECO INITIATIVES
    • CONTACT US
  • WRITE +
  • ABOUT US
  • HIRE US
Matplotlib Library

Python: Plots, Images, Contour and Pseudocolor in Matplotlib

by Prateek Kashyap March 12, 2022
written by Prateek Kashyap 0 comment 1382 views
Python: Plots, Images, Contour and Pseudocolor in Matplotlib
Python: Plots, Images, Contour and Pseudocolor in Matplotlib

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

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:

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( )
Code language: PHP (php)

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()
Code language: JavaScript (javascript)

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()
Code language: PHP (php)

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()
Code language: PHP (php)

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

  • Python Operators

    May 24, 2022
  • Host IT Smart – An Honest Review about this Indian Hosting Company

    May 24, 2022
  • Life cycle of a thread in Java

    May 24, 2022
  • Multithreading in Java

    May 23, 2022

EDUCATIONAL

  • 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

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

  • 10 mostly asked questions related to WhatsApp

  • Top 8 Programming Languages That Will Rule in 2022

  • Google Cloud Platform

  • Best Online Code Editors For Web Developers

  • How to Write a Synopsis for Project Work

CHEATSHEET

  • Git and Github 2022 Cheat Sheet

  • ReactJs Cheatsheet

  • Linux Commands Cheat Sheet

  • C Programming language Cheatsheet

  • Scala Cheatsheet

  • MySQL Cheatsheet

  • Javascript Cheatsheet

PROJECTS

  • Python Rock Paper Scissors Game

  • Currency Converter in Python

  • Alarm clock GUI application with tkinter

  • 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

TUTORIALS

  • JAVA TUTORIAL
  • COMPUTER NETWORK
  • DBMS TUTORIAL
  • E-COMMERCE TUTORIAL
  • KNOWLEDGE MANAGEMENT
  • C++ PROGRAMMING
  • COMPUTER NETWORK SECURITY
  • AMAZON WEB SERVICES

TECH NEWS

  • PyScript: Python in the Browser

  • HalloApp is a secure alternative to WhatsApp, made by two early WhatsApp employees

  • 5+ Best Humanoid Robots In The World

  • Windows 11 Now Official, Brings Fresh UI, Centrally-Placed Start Menu

TERMS & POLICY

  • PRIVACY POLICY
  • TERMS AND CONDITIONS

COMPILERS

  • JAVA COMPILER
  • PYTHON COMPILER
  • JS COMPILER
  • C++ COMPILER
  • C COMPILER

JOBS AND INTERNSHIPS

  • TCS off-campus hiring 2022 for software engineers- 2019, 2020, & 2021 Batches

    February 27, 2022
  • Deloitte Recruitment For Any Graduates as Learning Operations Associate Analyst

    February 18, 2022
  • HP Recruitment For Tech Support Intern Position

    February 16, 2022
  • EY Hiring- PAS Global Immigration Advanced Analyst

    February 14, 2022
  • Amazon Recruitment Drive for Virtual Customer Support Associate Position

    February 12, 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
    • UNIVERSITY PAPERS
    • MNC TWEETS
    • THINKECO INITIATIVES
    • CONTACT US
  • WRITE +
  • ABOUT US
  • HIRE US