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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:54:10+00:00 2026-06-04T17:54:10+00:00

I am using this example code as my starting code This code generates a

  • 0

I am using this example code as my starting code

This code generates a bar graph. When the user clicks on an actual bar on the bar graph, an event is triggered and the bounding box coordinates of the individual bar are displayed. This happens in the on_pick function.

I have modified the code so instead of a bar graph, I have a Axes3D line plot. I have several separate lines plotted on this XYZ coordinate system. What I need is to recognize which line was clicked. It appears that the bounding box does not work for the 3D plot as it did with the bar graph.

I have looked into the pick_event documentation but have been unsuccessful in finding a solution. I can simply detect the x,y coordinate of the location clicked, but because the plot can be rotated at any angle, it seems quite difficult to detect which line was actually clicked, especially since they can be overlapping depending on the point of view.

I appreciate your time and help!

  • 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-04T17:54:12+00:00Added an answer on June 4, 2026 at 5:54 pm

    If you only need to know which curve is clicked, it’s not very difficult. You need to create a line_picker() to check whether the mouse position is close enough to the curve or not.

    line_picker() need to calculate distance between point and line segments, that’s a little difficult, I walk around this problem by using linear interpolation of the curve.

    Here is the code, I interpolate the curve by 2000 points, and if the mouse position to the curve is less than 5 pixels, then the curve is selected.

    import matplotlib as mpl
    from mpl_toolkits.mplot3d import Axes3D
    import numpy as np
    import matplotlib.pyplot as plt
    
    def line_picker(line, me):
        if me.xdata is None: return False, dict()    
        x, y = me.x, me.y
        xdata, ydata = line.axes.transData.transform(np.array(line.get_data()).T).T
        index = np.arange(len(xdata))
        index2 = np.linspace(0, index[-1], 2000)
        xdata2 = np.interp(index2, index, xdata)
        ydata2 = np.interp(index2, index, ydata)
        d = np.sqrt((xdata2-x)**2. + (ydata2-y)**2.)
        if np.min(d) < 5:
            return True, {}
        else:
            return False, {}
    
    mpl.rcParams['legend.fontsize'] = 10
    
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
    z = np.linspace(-2, 2, 100)
    r = z**2 + 1
    x = r * np.sin(theta)
    y = r * np.cos(theta)
    line1 = ax.plot(x, y, z, label='parametric curve', picker=line_picker)[0]
    
    t = np.linspace(-1, 1, 100) 
    x = 4*np.sin(10*t)
    y = 4*np.cos(10*t)
    z = t**2*5-3
    
    line2 = ax.plot(x, y, z, label="second", picker=line_picker)[0]
    
    ax.legend()
    
    def onpick(event):
        print [line1, line2].index(event.artist)
    
    fig.canvas.mpl_connect('pick_event', onpick)
    
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this plugin: http://www.jeremymartin.name/projects.php?project=kwicks And my code follows this example: http://www.jeremymartin.name/examples/kwicks.php?example=7 I'm using
This is the example code, I'm using these functions for a program, but scanf
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
I am trying to use R2WinBUGS using this example: code (Please only consider the
I have an array list of objects and I am using this example to
I'm using the apache POI to read Word documents. I'm using this example as
Just using this as an example... Here are the columns in my UserProfile table:
I have looked at this example using php and GD to piecewise-render a spiral
From this example http://www.senchafiddle.com/#dPZn0 This displays a first panel, then a second one... using
I used this example (http://reecon.wordpress.com/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/) to upload file from android device to server, it

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.