secondary y axis matplotlib

Solutions on MaxInterview for secondary y axis matplotlib by the best coders in the world

showing results for - "secondary y axis matplotlib"
Theon
14 Jun 2019
1#We create a secondary y-axis for the definded column
2df.plot(secondary_y='name_of_column')
3plt.show()
Bruno
13 Jul 2018
1import numpy as np
2import matplotlib.pyplot as plt
3
4# Create some mock data
5t = np.arange(0.01, 10.0, 0.01)
6data1 = np.exp(t)
7data2 = np.sin(2 * np.pi * t)
8
9fig, ax1 = plt.subplots()
10
11color = 'tab:red'
12ax1.set_xlabel('time (s)')
13ax1.set_ylabel('exp', color=color)
14ax1.plot(t, data1, color=color)
15ax1.tick_params(axis='y', labelcolor=color)
16
17ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis
18
19color = 'tab:blue'
20ax2.set_ylabel('sin', color=color)  # we already handled the x-label with ax1
21ax2.plot(t, data2, color=color)
22ax2.tick_params(axis='y', labelcolor=color)
23
24fig.tight_layout()  # otherwise the right y-label is slightly clipped
25plt.show()
26
Lou-Ann
15 Apr 2016
1import numpy as np
2import matplotlib.pyplot as plt
3x = np.arange(0, 10, 0.1)
4y1 = 0.05 * x**2
5y2 = -1 *y1
6
7fig, ax1 = plt.subplots()
8
9ax2 = ax1.twinx()
10ax1.plot(x, y1, 'g-')
11ax2.plot(x, y2, 'b-')
12
13ax1.set_xlabel('X data')
14ax1.set_ylabel('Y1 data', color='g')
15ax2.set_ylabel('Y2 data', color='b')
16
17plt.show()
Olivia
18 Mar 2019
1import matplotlib.pyplot as plt
2import numpy as np
3import datetime
4import matplotlib.dates as mdates
5from matplotlib.transforms import Transform
6from matplotlib.ticker import (
7    AutoLocator, AutoMinorLocator)
8
9fig, ax = plt.subplots(constrained_layout=True)
10x = np.arange(0, 360, 1)
11y = np.sin(2 * x * np.pi / 180)
12ax.plot(x, y)
13ax.set_xlabel('angle [degrees]')
14ax.set_ylabel('signal')
15ax.set_title('Sine wave')
16
17
18def deg2rad(x):
19    return x * np.pi / 180
20
21
22def rad2deg(x):
23    return x * 180 / np.pi
24
25secax = ax.secondary_xaxis('top', functions=(deg2rad, rad2deg))
26secax.set_xlabel('angle [rad]')
27plt.show()
28
queries leading to this page
matplotlib two plots different y axisadd secondary axis matplotlibplot two different scales matplotlibmatplotlib diffrante scale axismatplotlib multiple axesadd a second axis in pythondifferent scale in matplotlibdouble y axis pythonpyplot x axiswhy my plot have double x axis pythonplot 2 y axis pythonmatplot lib scatter plot in different axisvarying scale for the y axis in matplotlibhow to change x axis values in matplotlibplot matplotlib graph with differnt axis valuespython dual y axisadd second y axis matplotlibadd already plotted axes on another axes pythonplot second axis pythonsecondary y axis matplotlibmake a second y axis wth clone x matplotlibtwo axis graph with matplotlibhow to plot charts for two axis in matplotlibpyplot add second y axiswhy x and y axis changed in matplotlibplot two scales on x axis matplotlib pyplotmatplotlib plot secondary y axissecond axis matplotlibdrawing secondary axis in matplotlibonly display two axis matplotlibhow to add a secondary azis pythonplt plot 2 y axismatplotlib add second y axisplotting two y axis on top of the same plot pythonmatplotlib with 2 y axespython graphing two axis on same scaletwo different y axes matplotlib 23set second y axis matplotlibpython matplotlib second y axissecondary axis pythonmatplotlib make scales of two plots equalplot two x axis matplotlibmatplotlib change x axispyplot second y axis labeldplot 2 axis pythonset x axis matplotlibhow to plot two y axis in pythonset x axis using matplotlibplot on different axis pythonhow to set x and y axis in matplotlib pandasplt second axismatplotlib making a plot with 2 y axismaplotlib plot graph with different axis sizesmatplotlib with two axisggplot second y axis scalepyplot dual axischange x axis matplotlibpython plot 2 y axismatplotlib dual y axismatplotlib dual axis lineschanging x axis values in matplotlibmatplotlib plt plot make second y axispython matplotlib how to make 2 axis graphpython plot two y axis single x axis with offestmatplotlib two plots with different y axismatplotlib plot two lines with different y axispython plot two lines different scalesax2 3d ax1 twinx 28 29add y axus matplotlibhow to plot graphs with different scale in pythonadd secondary x scale on a plot in pythondataframe plot 2 y axispython matplotlib two y axispython plot with two y axissecondary axis label matplotlibsecondary y label matplotlibmatplotlib 2 y axishow to plot wo plots with different axis pythonpython plot two y axisplot multiple lines with different scales matplotlibplot multiple axis matplotlibsecondary axis pyplot2 axis on same graph matplotplot secondary y axis matplotlibchange x axis values matplotlibmatplotlib ax secondary xaxistwo y axis plt pythonhow to plot with two y axis in pythonplt plot two axis ypython matplotlib second y axis labelhow to create a graph with two y axis in matplotlib pythonmatplotlib plot different scalesplot two graphs with different sacle pythonplt python how to create 2 axis plotmatplotlib multiple y axitwo scales matplotlibpython two y axisdrawing a graphs in python with different scalematplotlib pyplot plot multiple axesmatplotlib double y axisx axis values matplotlibdual axis plot in pythoncreate two scales on x axis matplotlib pythonmatplotlib line differente scalerspython second y axismatplotlib 2 ymatplotlib two axis single plotplot second y axis matplotlibplotting extra axis on right matplotlibsecondary y axis pltmultiple x axis matplotlibmatplotlib plot secondary axisplot double y axis pythonadd second y axis to plot matplotlibpython plot with two y axis bokaematplotlib how to put multiple y axis plotsmatplotlib two axessecondary y axis in axesmatlotlib different axishow to plot 2 axis matplotlibmatplotlib dual axismatplotlib secondary y axismatplotlib python plotting two y axis with different scale with same x axispython secondary y axismatplotlib double y axis with mutiple eachmatplotlib plot twinmatplotlib plot two different y axisplot on secondary axis matplotlibpyplot multiple axes2nd y label on right matplotlibplot two axes pythonplt 2 axespython double y axispython plot two graphs with different scaleplt plot two y axismatplotlib multiple y axis labelmatplotlib second x axis below how to set x and y axis in matplotlibadd secondary axis pythonhow to make 2 plot in 1 with two y labels matplotlibpython plot double y axishow to plot on secondary axis in python plotdifferent axis plotplotyy pythonplot second y axis pythonset x axis values matplotlibplot right away pyplotsecond y axis matplitlubmatplotlib plot with two different y axisax2 in pythonpython plot same axis example2 y axis plot matplotlib2 y axis in matplotlibpython matplotlib add second y axissecond y axis plotly pythonsecond y axis matplotlibpyplot two y axesmatplotlib plot on second y axismatplotlib separate y labelsdifferent scale for y ax in matplotlibpython plot different left and right y axismatplotlib change x axis valuespyplot multiple y axesset x axis to figure matplotlibpython plot adjust x axissecond y scale matplotlibmatplotlib set x axismatplotlib 2 axismatplotlib second y axismatplotlib line different scalesmultiple plot with different scales in matplotlibplot with two y axis pythontwo y axis in pythonmatplotlib two y axeshow to name y axis with two axis in pythonuse second y axis pltpython 2 line plots with different scaleshow to add a secondary axis in python matplotpython plot on secondary axissecond axis matplotlib y axisdouble axis mathplotlibdual axis chart pythondouble y axis matplotlibdrawing secondary axis in scatter plots in matplotlibname secondary axis in pythonhow to get two y axis in pythonhow to plot left and right y axis with x axis in pythonmatplotlib multiple y axispyplot second y axismatplotlib 2 axis one figurepython dual axis plotmatplotlib two y axis labeladd secondary y axis pythonmatplotlib multiple y axesmatplotlib right axismatplotlib different y axistwo axis plot matplotlibadd another axis pythonplot graph with 2 y axis matplotlibhow to add secondary axis in pythonmatplotlib pyplot set second y axis labeltwo y axis matplotlibplt plot secondary y axisplot two y axis pythonmatplotlib double yaxis plotpython plot 2 axisplot multiple y axis pythontwo axis matplotlibmatplotlib double axis plotsecond y axis matplotlibhow to change x axis matplotlibcombine top two plots in matplotlibe 2 2a 2 subplotssecondary y axis matplotlib