[Python] Set the graph range with matplotlib

Background: We needed a program to adjust the graph when dealing with small and large data at the same time or when small changes are not so important.

For the time being, it is only necessary to be able to set the range of the axes of the graph.

Operating environment: Linux (Ubuntu 16.04.2 LTS), python3.6.2, matplotlib (2.0.2)

Purpose: Specify the axis range of the graph Take the average value of the array with numpy and set the upper and lower digits of it to the maximum and minimum of the graph.

Also, when entering a value directly to specify the range of the graph set_ylim([min,max]) To use.

(Source code)

#Array x,x in the graph to y respectively,Contains y-worthy data.*/
import matplotlib
import numpy as np
import matplotlib.pyplot as plt

#(abridgement)
#Calculate the average value of y#
ave=np.average(y)

ax=plt.subplot()
ax.plot(x,y,linewidth=0.3)
ax.grid(which="both")
ax.set_xlabel("x")
ax.set_ylabel("y")

#Set of ranges
ax.set_ylim([ave*0.1,ave*10])

plt.show()

Recommended Posts

[Python] Set the graph range with matplotlib
Set the xticklabels color individually with matplotlib
Heatmap with Python + matplotlib
Band graph with matplotlib
[Python] limit axis of 3D graph with Matplotlib
Read Python csv data with Pandas ⇒ Graph with Matplotlib
Increase the font size of the graph with matplotlib
The basis of graph theory with matplotlib animation
Graph Excel data with matplotlib (1)
[Python] How to draw a line graph with Matplotlib
[Introduction to Python] How to iterate with the range function?
[Python] Get the numbers in the graph image with OCR
Visualize the range of interpolation and extrapolation with python
Graph drawing method with matplotlib
Graph Excel data with matplotlib (2)
Call the API with python3.
Display the graph while changing the parameters with PySimpleGUI + Matplotlib
Study math with Python: Draw a sympy (scipy) graph with matplotlib
[Python] Read the csv file and display the figure with matplotlib
Create plot animation with Python + Matplotlib
A python graphing manual with Matplotlib.
[Python] font family and font with matplotlib
Set python compile options with pyenv
Draw a loose graph with matplotlib
Get the weather with Python requests
Get the weather with Python requests 2
Find the Levenshtein Distance with python
Hit the Etherpad-lite API with Python
Install the Python plugin with Netbeans 8.0.2
Output the call graph with PyCallGraph
I liked the tweet with python. ..
Heatmap with Dendrogram in Python + matplotlib
Master the type with Python [Python 3.9 compatible]
Let's make a graph with python! !!
Draw Lyapunov Fractal with Python, matplotlib
When matplotlib doesn't work with python2.7
Lognormal probability plot with Python, matplotlib
Graph Based Segmentation with Python + OpenCV
The first step in Python Matplotlib
Make the Python console covered with UNKO
Adjust the spacing between figures with Matplotlib
[pyqtgraph] Set the size ratio of the graph
Align the size of the colorbar with matplotlib
Behind the flyer: Using Docker with Python
Check the existence of the file with python
[Python] Get the variable name with str
[Python] Round up with just the operator
Display Python 3 in the browser with MAMP
Search the maze with the python A * algorithm
Associate the table set in python models.py
Let's read the RINEX file with Python ①
Working with OpenStack using the Python SDK
Download files on the web with Python
[Python] Let's make matplotlib compatible with Japanese
Graph trigonometric functions with numpy and matplotlib
Display markers above the border with matplotlib
Learn the design pattern "Singleton" with Python
[Python] Automatically operate the browser with Selenium
Set the process name of the Python program
Match the colorbar to the figure with matplotlib
Learn the design pattern "Facade" with Python