The Wayback Machine - https://web.archive.org/web/20240910211916/https://www.geeksforgeeks.org/change-the-x-or-y-interval-of-a-matplotlib-figure/
Open In App

Change the x or y interval of a Matplotlib figure

Last Updated : 03 Jan, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

It is quite easy to change the x or y range using matplotlib.pyplot.xlim() and matplotlib.pyplot.ylim() from the Matplotlib is a library in Python. This function in pyplot module of matplotlib library is used to get or set the x-limits/ y-limits of the current axes and returns the tuple of the new x-axis/y-axis limits.

Syntax: matplotlib.pyplot.xlim(*args, **kwargs)

Parameters: 

*args:

  •  left: This parameter is used to set the xlim/ylim to left.
  • right: This parameter is used to set the xlim/ylim to right.

 **kwargs: This is Text properties that is used to control the appearance of the labels.

Example 1: Without using matplotlib.pyplot.xlim()/matplotlib.pyplot.ylim() function.

Python3




import numpy as np
import matplotlib.pyplot as plt
  
x = [0, 5, 9, 10, 15, 20, 25]
y = [0, 1, 2, 3, 4, 5, 6]
  
plt.plot(x, y)
plt.show()


Output:

Example 2: With the matplotlib.pyplot.xlim()/matplotlib.pyplot.ylim() function.

Python3




import numpy as np
import matplotlib.pyplot as plt
  
x = [0,5,9,10,15,20,25]
y = [0,1,2,3,4,5,6]
plt.xlim([-40, 40])
plt.ylim([-40, 40])
  
plt.plot(x,y)
plt.show()


Output:-



Similar Reads

Matplotlib.figure.Figure() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure() class This c
2 min read
Matplotlib.figure.Figure.add_artist() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.add_artist() f
2 min read
Matplotlib.figure.Figure.add_axes() in Python
Matplotlib is a library in Python and it is a numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top-level containers for all plot elements. matplotlib.figure.Figure.add_axes()
2 min read
Matplotlib.figure.Figure.add_gridspec() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.add_gridspec()
2 min read
Matplotlib.figure.Figure.add_subplot() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.add_subplot()
2 min read
Matplotlib.figure.Figure.align_labels() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.align_labels()
2 min read
Matplotlib.figure.Figure.align_xlabels() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.align_xlabels(
2 min read
Matplotlib.figure.Figure.align_ylabels() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.align_ylabels(
2 min read
Matplotlib.figure.Figure.autofmt_xdate() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.autofmt_xdate(
2 min read
Matplotlib.figure.Figure.clear() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.clear() functi
1 min read
Matplotlib.figure.Figure.clf() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.clf() function
1 min read
Matplotlib.figure.Figure.colorbar() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.colorbar() fun
2 min read
Matplotlib.figure.Figure.delaxes() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.delaxes() func
2 min read
Matplotlib.figure.Figure.draw() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.draw() functio
1 min read
Matplotlib.figure.Figure.get_constrained_layout_pads() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_constraine
2 min read
Matplotlib.figure.Figure.get_constrained_layout() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_constraine
2 min read
Matplotlib.figure.Figure.draw_artist() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.draw_artist()
2 min read
Matplotlib.figure.Figure.figimage() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.figimage() fun
2 min read
Matplotlib.figure.Figure.gca() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.gca() method T
2 min read
Matplotlib.figure.Figure.get_axes() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_axes() met
2 min read
Matplotlib.figure.Figure.get_children() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_children()
2 min read
Matplotlib.figure.Figure.dpi() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.dpi method The
2 min read
Matplotlib.figure.Figure.get_default_bbox_extra_artists() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_default_bb
2 min read
Matplotlib.figure.Figure.get_dpi() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_dpi() meth
2 min read
Matplotlib.figure.Figure.get_edgecolor() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_edgecolor(
2 min read
Matplotlib.figure.Figure.get_facecolor() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_facecolor(
2 min read
Matplotlib.figure.Figure.get_figheight() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_figheight(
2 min read
Matplotlib.figure.Figure.get_figwidth() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_figwidth()
2 min read
Matplotlib.figure.Figure.get_frameon() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_frameon()
2 min read
Matplotlib.figure.Figure.get_size_inches() in Python
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.get_size_inche
2 min read
Article Tags :
Practice Tags :