Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9151073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:42:44+00:00 2026-06-17T11:42:44+00:00

I draw a figure relating two y-axis (i.e. two different S.I. scale) to a

  • 0

I draw a figure relating two y-axis (i.e. two different S.I. scale) to a single x-axis. I have to zoom on some value and I manage it with the zoom_inset_locator trick from Matplotlib. I achieve the zoom axes but I am missing the second y-axis (see example below):

Two-y axis and an inset zoom

It did try to add a second axis using twinx() again, but it failed as it plot the axis on the main twinx (right) axis but leave blank ticks on the zoom right axis and seems to give the x-axis the right treatment, see below:

enter image description here

Is there any workaround? Here is the code I used to draw the figure:

import numpy,os,sys
import pylab
import scipy.optimize
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset

# Initializing the curve
fig_cal=pylab.figure()
host_weight = fig_cal.add_subplot(111)
host_mass = host_weight.twinx()
Tension = numpy.linspace(0,0.08,100)
Weight = 0.5* Tension
Mass = Weight/9.81

# Plotting the curve

host_weight.plot(Tension, Weight, 'r', label='Fitted line',lw=2)
host_mass.plot(Tension, Mass)

# Cosmetic on the Figure
host_weight.set_xlabel("Tension U [$V$]")
host_weight.set_ylabel("Weight F [$N$]")
host_mass.set_ylabel("Mass M [$kg$]")
host_mass.set_ylim(host_weight.axis()[-2]/9.81, host_weight.axis()[-1]/9.81)
host_weight.grid(False)

# Zoom on the first measurement
zoom_weight = zoomed_inset_axes(host_weight, zoom = 7.5, bbox_to_anchor=(0.95,0.5), bbox_transform=host_weight.transAxes)
zoom_weight.plot(Tension[:4], Weight[:4], 'r', lw=2)
zoom_weight.set_xticks(zoom_weight.xaxis.get_majorticklocs()[::2])
zoom_weight.set_yticks(zoom_weight.yaxis.get_majorticklocs()[::2])
# zoom_mass = zoom_weight.twinx()

# zoom_mass.plot(Tension[:4], Mass[:4],alpha=0)
# zoom_mass.set_ylim(zoom_weight.axis()[-2]/9.81,zoom_weight.axis()[-1]/9.81)
mark_inset(host_weight, zoom_weight, loc1=2, loc2=4, fc="none", ec="0.5")

pylab.show()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:42:46+00:00Added an answer on June 17, 2026 at 11:42 am

    So I found the answer to my question… Sorry for the delay, but I put this issue on hold… I did find the bug but just a workaround by generating an another zoom inset, using the alpha canal and disabling a lot of stuff…

    Here is my code:

    import numpy,os,sys
    import pylab
    from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
    from mpl_toolkits.axes_grid1.inset_locator import mark_inset
    
    # Initializing the curve
    fig_cal=pylab.figure()
    host_weight = fig_cal.add_subplot(111)
    host_mass = host_weight.twinx()
    Tension = numpy.linspace(0,0.08,100)
    Weight = 0.5* Tension
    Mass = Weight/9.81
    
    # Plotting the curve
    host_weight.plot(Tension, Weight, 'r', label='Fitted line',lw=2)
    host_mass.plot(Tension, Mass, alpha=0)
    
    # Cosmetic on the Figure
    host_weight.set_xlabel("Tension U [$V$]")
    host_weight.set_ylabel("Weight F [$N$]")
    host_mass.set_ylabel("Mass M [$kg$]")
    host_mass.set_ylim(host_weight.axis()[-2]/9.81, host_weight.axis()[-1]/9.81)
    host_weight.grid(False)
    
    # Zoom on the first measurement
    zoom_weight = zoomed_inset_axes(host_weight, zoom = 7.5, bbox_to_anchor=(0.95,0.5), bbox_transform=host_weight.transAxes)
    zoom_weight.plot(Tension[:4], Weight[:4], 'r', lw=2)
    zoom_weight.set_xticks(zoom_weight.xaxis.get_majorticklocs()[::2])
    zoom_weight.set_yticks(zoom_weight.yaxis.get_majorticklocs()[::2])
    zoom_mass = zoomed_inset_axes(host_mass, zoom = 7.5, bbox_to_anchor=(0.95,0.5),     bbox_transform=host_mass.transAxes)
    zoom_mass.xaxis.set_visible(False)
    zoom_mass.spines['left'].set_visible(False)
    zoom_mass.spines['top'].set_visible(False)
    zoom_mass.patch.set_alpha(00)
    zoom_mass.yaxis.tick_right()
    zoom_mass.yaxis.set_label_position('right')
    zoom_mass.yaxis.set_offset_position('right')
    zoom_mass.plot(Tension[:4], Mass[:4],color='w', alpha=0)
    zoom_mass.set_ylim(zoom_weight.axis()[-2]/9.81,zoom_weight.axis()[-1]/9.81)
    
    pylab.show()
    

    Maybe not the best way, but it works !!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to draw a figure something like this: I need to have
I'm trying to figure out how the books draw a box perhaps with different
I have code to draw a pie chart with value and random colors. Now
I am using the DrawRect method to draw some text and can't figure out
I have a figure of size 14 x 14 square drawn inside an axis
I'm trying to figure out a simple to draw some text in OpenGL. My
Can anybody suggest me a simple software to draw a figure something like in
A very simple base class: class Figure { public virtual void Draw() { Console.WriteLine(Drawing
I'm using CALayers to draw to a UITableViewCell. I'm trying to figure out how
To draw a circle on map I have a center GLatLng (A) and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.