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

  • SEARCH
  • Home
  • 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 8545867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:53:24+00:00 2026-06-11T12:53:24+00:00

Okay I’m totally stuck with a Python problem. I think describing the problem in

  • 0

Okay I’m totally stuck with a Python problem. I think describing the problem in too much detail is confusing, so I will summarise the problem and then show the code I have.

I have created an imshow plot, over the top of which, I would like to plot a regular line plot. The Y axis is different, which is fine, but the X axes should be the same for both.

It almost works, apart from the scaling:

fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.set_xlabel('MJD',fontsize=14)
ax1.set_ylabel('Bin Number',fontsize=14)
mjdaxis=np.linspace(0,bad_removed_mjd.shape[0]-1,20).astype('int')
ax1.set_xticks(mjdaxis,[int(np.floor(bad_removed_mjd[i])) for i in mjdaxis])
ax1.imshow(residuals, aspect="auto")

ax2 = ax1.twinx()
ax2.set_ylabel('Pdot (s-2)',fontsize=14)
ax2.plot(pdot[8:,0],pdot[8:,1])

plt.show()

Now what happens is that the imshow plot gets squashed between values 0-60 or so on the x axis. This is because they are now getting plotted by their index number 0,1,2…. I need their x axis values to correspond to the value in the list ‘bad_mjd_removed’ 55304, 55365, 55401…. This works fine when I just have the imshow plot on its own.

Here are pictures of the imshow plot on its own, and then when I try to add the line plot over it:

plot with imshow only
plot with imshow and line plot

On the second plot, the thin line at around 0 on the x axis is the whole of picture 1 squeezed inbetween 0 and 60.

I would be very grateful of any help on this problem. Thank you.

  • 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-11T12:53:25+00:00Added an answer on June 11, 2026 at 12:53 pm

    You can use extent kwarg to put your imshow plot in the right place. As an added bonus, you should be able to let matplotlib handle the axis tickmarks automatically if you’ve done this too.

    import matplotlib.pyplot as plt
    import numpy as np
    x = np.random.rand(2,3)
    plt.imshow(x, interpolation='nearest', extent=[0,3,0,2])
    

    enter image description here

    plt.imshow(x, interpolation='nearest', extent=[100,103,100,102])
    

    enter image description here

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

Sidebar

Related Questions

Okay, I have GOT to be missing something totally rudimentary here. I have an
Okay, so the answer to my question might not be the problem but here's
Okay, so I'm not even sure how to ask this question (much less search
Okay, so I have the weirdest problem right now. My code is fine! It
Okay say your using a app, and you opened a new activity and then
Okay, I hate facebook now. I've been fighting with this far too long. I'm
Okay i have this problem with every page i make. im not sure what
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay this question is very simple: I have a facebook page, and a website.
Okay, I feel a bit foolish for having to ask this but I guess

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.