Instantly create a diagram of 2D data using python's matplotlib

If you have 2D data that you want to check immediately what the contents are, you can instantly create a diagram of that data by creating the following function in python in advance. For those who don't care about the detailed settings in the figure and just want to be easy.

quick.py


def draw(data,cb_min,cb_max):  #cb_min,cb_max:Values at the bottom and top of the colorbar
    import numpy as np
    import matplotlib.pyplot as plt
    X,Y=np.meshgrid(np.arange(data.shape[1]),np.arange(data.shape[0]))
    plt.figure(figsize=(10,4))  #Specify the aspect ratio of the figure
    div=20.0                    #How many colors to use to draw the figure
    delta=(cb_max-cb_min)/div
    interval=np.arange(cb_min,abs(cb_max)*2+delta,delta)[0:int(div)+1]
    plt.contourf(X,Y,data,interval)
    plt.show()

with this, In[10]: import quick In[11]: quick.draw(data,-2,32) If you execute, the contents of the 2D array created by numpy will be output as a color contour diagram. t.png

(Example: Global sea surface temperature distribution in January)

** When you want to adjust the orientation of the figure **

** When you want to flip the figure left and right **

In[12]: quick.draw(data[:,::-1],-2,32) lr.png

** When you want to flip the figure upside down **

In[12]: quick.draw(data[::-1,:],-2,32) ud.png

** When you want to rotate the figure 90 degrees **

In[12]: quick.draw(data[:,::-1].transpose(),-2,32) Invert left and right and then transpose transpose.png

** When you want to rotate the figure 180 degrees **

In[12]: quick.draw(data[::-1,:][:,::-1],-2,32) Flip upside down and then flip left and right 180.png


Reference URL: http://seesaawiki.jp/met-python/d/matplotlib

Recommended Posts

Instantly create a diagram of 2D data using python's matplotlib
A memorandum of using Python's input function
Create multiple line charts from a data frame at once using Matplotlib
Create 3D printer data (STL file) using CadQuery
Create a binary data parser using Kaitai Struct
Create interactive 3D graphs on JupyterLab using matplotlib
Create a data collection bot in Python using Selenium
Create dummy data using Python's NumPy and Faker packages
Python: Diagram of 2D data distribution (kernel density estimation)
[Python] How to create a 2D histogram with Matplotlib
Try to create a battle record table with matplotlib from the data of "Schedule-kun"
A network diagram was created with the data of COVID-19.
Let's create a PRML diagram with Python, Numpy and matplotlib.
Data visualization method using matplotlib (1)
Create a dummy data file
Data visualization method using matplotlib (2)
Create a correlation diagram from the conversation history of twitter
A memorandum of using eigen3
Create an API that returns data from a model using turicreate
How to create a large amount of test data in MySQL? ??
Data visualization method using matplotlib (+ pandas) (5)
Create a python GUI using tkinter
Create a nested dictionary using defaultdict
Data visualization method using matplotlib (+ pandas) (3)
Recommendation of data analysis using MessagePack
A story about using Python's reduce
Create a CRUD API using FastAPI
Data visualization method using matplotlib (+ pandas) (4)
Create a C wrapper using Boost.Python
Using graph drawing using Python's Matplotlib + Seaborn on Windows, a non-Python execution environment
Visualization of latitude / longitude coordinate data (assuming meteorological data) using cartopy and matplotlib
I tried to perform a cluster analysis of customers using purchasing data
[Python] [Word] [python-docx] Try to create a template of a word sentence in Python using python-docx
Getting a combination of elements using itertools
[Python] Extension using inheritance of matplotlib (NavigationToolbar2TK)
A complete understanding of Python's asynchronous programming
How to draw a graph using Matplotlib
Flexible animation creation using animation.FuncAnimation of matplotlib
Make a relation diagram of Python module
Create a graph using the Sympy module
Create a GUI app with Python's Tkinter
Impressions of using Flask for a month
[Python] Create a Batch environment using AWS-CDK
External display of matplotlib diagrams using tkinter
A complete understanding of Python's object-oriented programming
Creating a data analysis application using Streamlit
Separation of design and data in matplotlib
Create document classification data quickly using NLTK
Multiply a 3D array using Numpy's einsum
Create a dataframe from excel using pandas
I tried 3D detection of a car
Awareness of using Aurora Severless Data API
Create a graph with borders removed with matplotlib
A memorandum of trouble when formatting data
Plot the environmental concentration of organofluorine compounds on a map using open data
A quick reference chart of matplotlib needed to draw a diagram to convince your boss
I want to create a web application that uses League of Legends data ①
Paste a link to the data point of the graph created by jupyterlab & matplotlib
[AWS Lambda] Create a deployment package using the Docker image of Amazon Linux