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 6848513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:52:39+00:00 2026-05-27T00:52:39+00:00

I have several plt.plot instances and I wanted to only plt.show() certain objects. To

  • 0

I have several plt.plot instances and I wanted to only plt.show() certain objects. To illustrate here is some code:

import matplotlib.pyplot as plt

ax1 = plt.plot(range(5),range(5))
ax2 = plt.plot([x+1 for x in range(5)],[x+1 for x in range(5)])
ax3 = plt.plot([x+2 for x in range(5)],[x+2 for x in range(5)])

#plt.show([ax1,ax2])
plt.show()

So I would like something like the commented out statement, to display only ax1 & ax2 in the example figure.

  • 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-05-27T00:52:39+00:00Added an answer on May 27, 2026 at 12:52 am

    You can remove some of the plotted lines from the set of lines of the current axes:

    axes = plt.gca()  # Get current axes
    axes.lines.remove(ax2[0])  # Removes the (first and only) line created in ax2
    plt.draw()  # Updates the graph (in interactive mode)
    

    If you want to put it back, you can similarly do

    axes.lines.append(ax2[0])  # Puts the line back (the drawing order is changed, here)
    

    You could alternatively save the current graph lines, if you need to put them back later:

    all_lines = list(axes.lines)  # Copy
    # ...
    axes.lines[:] = all_lines  # All lines put back
    

    The key point is that each plot() command adds a line to the current axes and draws it (in interactive mode). So you can either remove already plotted lines (like in this answer).

    As Yann pointed out, you can also make some lines invisible. However, the method from this answer is probably faster, since there are fewer lines to be drawn (if this matters).

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

Sidebar

Related Questions

I have several problems relating to NSPredicates, here are they; 1.) My code is
I have several tables whose only unique data is a uniqueidentifier (a Guid) column.
I have several objects such as rectangle buttons, switches, UIlabels etc on my view,
I have several classes that I serialize/deserialize, each with a number of properties, some
I have several objects, like products, order, etc. When I get information from my
I have several objects in the database. Url to edit an object using the
We have several Visual Studio projects, and we would like to: enable/disable some defines
I have several instances where a form is brought into the page in an
I have a simple plot with several sets of points and lines connecting each
I have several matlpotlib functions rolled into some django-celery tasks. Every time the tasks

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.