For questions about the matplotlib twinx method, which creates a new Axes with an invisible x-axis and an independent y-axis positioned opposite to the original one (i.e. at right).
Questions tagged [twinx]
70 questions
1
vote
1 answer
twinx or twinx-like supylabel for matplotlib subplots?
Given the subplots setup shown below, is there any possibility to add a super y label at the right side of the plot analogously to the 'Green label'?
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2,…

corinna
- 629
- 7
- 18
1
vote
1 answer
tick_params doesn't work properly for 2nd y-axis
I am designing a GUI in which whenever I click a button, the figure inside the GUI will be updated. This figure contains two y-axes with a common x-axis. I am using twinx function inside matplotlib. Everything is working as expected, except the…

Rex
- 13
- 1
- 6
1
vote
0 answers
Double y axis in a subplot
I would like to have a double y-axis in one of my subplots; however, it seems like I am missing something about twinx() and link = :x, but I couldn't figure out what..
Plotting double y-axis using twinx() works fine in a standard plotting frame.…

Vautrin Balzac
- 53
- 5
1
vote
1 answer
Pandas plot dual axis using only numerical values
I have dataframe like this,
import pandas as pd
from matplotlib import pyplot as plt
data = {
"TIMEFRAME": ["9/12/2014 17:52", "10/12/2014 5:02", "10/12/2014 8:04"],
"Volumetric Flow Meter 1": [0.82, 0.88, 0.9],
"Pump Speed (RPM)":…

Tahsin Alam
- 147
- 1
- 10
1
vote
1 answer
Subplots and twinx axis
I was trying to make two subplots with twinx axis, 3 curves (curvey,curve1 and curve2) on the first subplot and 3 curves (curvey, curve3 and curve4) on the second subplot. But I'm not getting what I want. I wonder if you guys can help me please.
x =…

Jerick Rodriguez
- 56
- 6
1
vote
1 answer
How to have 2 different scales on same Y axis in Python using Matplotlib
I need to draw 4 X vs Y plots, where X is constant but different Y Values. I used below code to get the plots but need to show the Y scale on either side of the Secondary Y axes (Y Axis 2 in the image), the way Primary Y Axis has (both inward and…
user11734037
1
vote
1 answer
Python (twinx plot) Wacky graph
Edit: The graph is fixed now but I am having troubles plotting the legend. It only shows legend for 1 of the plots. As seen in the picture below
I am trying to plot a double axis graph with twinx but I am facing some difficulties as seen in the…

HOA
- 111
- 2
- 14
1
vote
1 answer
Cannot get plot to correctly plot 2 y series with their corresponding dates on x-axis?
Attempting to plot two sets of arrays. x against y and x1 against y1 on the same graph. The datetime values are different between the two sets but the y and y1 are plotted according to the same x values which not what is written in the arrays (the…

Sam Capp
- 25
- 3
1
vote
0 answers
Matplotlib broken twin x-axis
I am trying to generate a matplotlib plot that consists of two subplots that share an x-axis.
One subplot plots two sets of data on different y-axis scales, and the other just plots one set of data.
I would also like to "break" the x-axis of both…

Neal
- 31
- 2
1
vote
0 answers
Align x and y axis with twinx twiny in log scale
I want to create a plot with two x axis and also two y axis. I am using twiny and twinx to do it. The secondary axis are just a rescaling of the original ones, so I'm applying a transformations to get the ticks. The problem is that I am in log…

rseppi
- 21
- 3
1
vote
1 answer
interactive legend with twinx - matplotlib
i want to create a plot with two y-axis and interactive legend. I made a minimal "working" example based on: https://matplotlib.org/3.1.1/gallery/event_handling/legend_picking.html
import matplotlib.pyplot as plt
import numpy as np
t =…

Cyruu Kairoo
- 13
- 6
1
vote
2 answers
matplotlib axis label lost when increasing y tick labels for subplot
why are the y-axis labels lost when specifying: ax.set_yticklabels(ax.get_yticklabels(), fontsize=16)
%pylab inline
import pandas as pd
import seaborn as sns; sns.set()
df = pd.DataFrame({'dt':['2020-01-01', '2020-01-02', '2020-01-03',…

Georg Heiler
- 16,916
- 36
- 162
- 292
1
vote
1 answer
Rotating 2nd y-axis tick labels
I need to rotate the 2nd y-axis ticklabel and add a label for this axis as well in the figure below
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import matplotlib.transforms as mtransforms
fig, ax1 =…

Ahmed Attia
- 153
- 1
- 8
1
vote
1 answer
matplotlib twinx() 2nd axis markers on the same left axis
Say I create a secondary y-axis with twinx() similar to this demo
Is there a way I can place the tick marks and values of the secondary y-axis on the left side immediately next to the existing y-axis such as below ?

XYZ
- 310
- 2
- 12
1
vote
1 answer
In matplotlib, pyplot.text disappears when applying twinx. How can it appear?
plt.text(x, y, text) is working when I use single y-axis but it disappears when I apply twinx. Can it be fixed?
fig, ax = plt.figure(figsize=(8,6))
text = "E_rms(test) = {:7.3f}/nE_maxres =…

Joonho Park
- 511
- 5
- 17