Questions tagged [twinx]

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).

70 questions
23
votes
3 answers

Align twinx tick marks

Is it possible to make a plot with two independent y-axes such that the tick marks align? Below is an example of half of the solution. I've doubled the y-axis using twinx, but the tick marks aren't aligned and the gridlines form an awkward pattern…
juniper-
  • 6,262
  • 10
  • 37
  • 65
13
votes
2 answers

trouble aligning ticks for twinx axes

I created a matplotlib plot that has 2 y-axes. The y-axes have different scales, but I want the ticks and grid to be aligned. I am pulling the data from excel files, so there is no way to know the max limits beforehand. # creates double-y axis ax2 =…
amanda_mays
  • 155
  • 1
  • 7
13
votes
3 answers

Data being plotted over legend when using twinx

I'm trying to use Python and Matplotlib to plot a number of different data sets. I'm using twinx to have one data set plotted on the primary axis and another on the secondary axis. I would like to have two separate legends for these data sets. In…
0235ev
  • 197
  • 1
  • 8
12
votes
4 answers

Aligning two y-axis around zero

I have a plot with two y-axis on a shared x-axis, and I want to make them align at y=0 so that I can draw a horizontal line to highlight the zero tick. currently the two axis are not aligned and I have to draw two line which is terrible. How can I…
dingx
  • 1,621
  • 3
  • 20
  • 38
6
votes
1 answer

set_markersize not working for right side axis

I'm messing around with some plot styles and ran into a curiosity. I have a plot with twinx() to produce ticks on the right-hand side as well as the left. I want to stagger some ticks, some going farther out that others. I can add padding to any…
likethevegetable
  • 264
  • 1
  • 4
  • 17
6
votes
1 answer

Rotate x axis labels of subplots with twinx

I'm trying to rotate the x axis labels on the subplots created in this question. Unfortunately, my modification to the example code here seems to have no effect on the x axis labels: import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1…
Alex S
  • 4,726
  • 7
  • 39
  • 67
4
votes
1 answer

Dual x-axis in python: same data, different scale

I'd like to plot some data in Python using two different x-axes. For ease of explanation, I will say that I want to plot light absorption data, which means I plot absorbance vs. wavelength (nm) or energy (eV). I want to have a plot where the bottom…
quantum girl
  • 53
  • 2
  • 8
4
votes
1 answer

Color multiple twinx() axes

I'm currently using matplotlib within Sage to plot some data. I have made it possible to add multiple y axes using this example: from mpl_toolkits.axes_grid1 import host_subplot import mpl_toolkits.axisartist as AA import matplotlib.pyplot as…
MEvans
  • 301
  • 1
  • 3
  • 8
3
votes
1 answer

How can I plot a secondary y-axis with seaborn's barplot?

I'm trying to plot the data (see below). With company_name on the x-axis, status_mission_2_y on the y axis and percentage on the other y_axis. I have tried using the twinx() fucntion but I can't get it to work. Please can you help? Thanks in…
johnadem
  • 153
  • 2
  • 12
3
votes
2 answers

matplotlib twinx strange behavior after set_position()

I'm working on a function that would make it easy for me to add parasite axes wherever I want on a plot, but I have encountered a weird situation. Take a look at the following code: import matplotlib.pyplot as…
Amine Kchouk
  • 162
  • 1
  • 11
3
votes
0 answers

Axis, ticks and label not aligned for third xaxis using twiny()

I want to have three horizontal axis and for each axis the ticks and labels should be right next to their respective axis. My attempt: import matplotlib.pyplot as plt import numpy as np T = range(30,60) Q1 = range(100,400,10) fig =…
mangoon
  • 31
  • 2
3
votes
2 answers

Define aspect ratio when using twinx in new version of matplotlib

Current version of matplotlib do not allow box-forced anymore, how should I do the same thing as the answer? I am using matplotlib 3.1.0. After I ploted another set of data on the same plot with twinx() function, I want to change the aspect ratio of…
snail123815
  • 303
  • 1
  • 3
  • 10
2
votes
3 answers

Add a matplotlib legend that covers the lines of the twinx axis

I have this python code. it twinx the axis ax and plots some function on both axis I plot the legend on ax1 The problem is that the legend is not covering the curves of ax2 It is possible to automatically positioning the legend on ax by covering…
Giggi
  • 681
  • 2
  • 9
  • 17
2
votes
1 answer

How do you controle zorder across twinx in matplotlib?

I'm trying to control the zorder of different plots across twinx axes. How can I get the blue noisy plots to appear in the background and the orange smoothed plots to appear in the foreground in this plot? from matplotlib import pyplot as plt import…
Jeff
  • 53
  • 3
2
votes
0 answers

twinx non-linear mapping between shared y axes on a plot in matplotlib

I have some 3d data that I am plotting with pcolormesh. On the x-axis is time, on the y-axis is height. The height has a potential (E) associated with it, but the mapping from height (y) to potential (E) is non-linear. I want to add an axis on the…
FluidFox
  • 107
  • 10
1
2 3 4 5