Matplotlib.pyplot.twiny() in Python Last Updated : 11 Apr, 2020 Comments Improve Suggest changes Like Article Like Report Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. Sample Code Python3 1== # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 8]) plt.show() Output: matplotlib.pyplot.twiny() Function The twinx() function in pyplot module of matplotlib library is used to make and return a second axes that shares the y-axis. Syntax: matplotlib.pyplot.twiny(ax=None) Parameters: This method does not accepts any parameters. Returns: This returns the second axes that shares the x-axis Below examples illustrate the matplotlib.pyplot.twiny() function in matplotlib.pyplot: Example #1: Python3 1== # Implementation of matplotlib function import matplotlib.pyplot as plt import numpy as np def GFG1(temp): return (5. / 9.) * (temp - 32) def GFG2(ax1): y1, y2 = ax1.get_ylim() ax_twin .set_ylim(GFG1(y1), GFG1(y2)) ax_twin .figure.canvas.draw() fig, ax1 = plt.subplots() ax_twin = ax1.twiny() ax1.callbacks.connect("ylim_changed", GFG2) ax1.plot(np.linspace(10, 120, 100)) ax1.set_xlim(0, 40) ax1.set_xlabel('Fahrenheit') ax_twin .set_xlabel('Celsius') fig.suptitle('matplotlib.pyplot.twiny() function\ Example\n\n', fontweight ="bold") plt.show() Output: Example #2: Python3 1== # Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt # Create some mock data t = np.arange(0.01, 20.0, 0.001) data1 = np.exp(t) data2 = np.sin(0.3 * np.pi * t) fig, ax1 = plt.subplots() color = 'tab:blue' ax1.set_ylabel('time (s)') ax1.set_xlabel('exp', color = color) ax1.plot(data1, t, color = color) ax1.tick_params(axis ='x', labelcolor = color) ax2 = ax1.twiny() color = 'tab:green' ax2.set_xlabel('sin', color = color) ax2.plot(data2, t, color = color) ax2.tick_params(axis ='x', labelcolor = color) fig.suptitle('matplotlib.pyplot.twiny() function\ Example\n\n', fontweight ="bold") plt.show() Output: Comment More infoAdvertise with us Next Article Matplotlib.pyplot.twiny() in Python S SHUBHAMSINGH10 Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads Matplotlib.pyplot.twinx() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. Sample Code Python3 1== # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 8 2 min read Matplotlib.pyplot.sci() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.yticks() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. Matplotlib.pyplot.yticks() Function The annotate() function in pyplot module of matplotlib library is use 2 min read Matplotlib.pyplot.xlim() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.show() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. Sample Code - Python3 1== # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 2 min read Matplotlib.pyplot.triplot() in python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.sca() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 1 min read Matplotlib.pyplot.quiver() in Python Matplotlib is a library of Python bindings which provides the user with a MATLAB-like plotting framework. Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits like Tkinter, awxPython, etc. Matplotlib.pyplot.qui 2 min read Matplotlib.pyplot.tricontour() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 3 min read Matplotlib.pyplot.tripcolor() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. Sample Code Python3 1== # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 8 4 min read Like