Python Forum
pylab, labeling points on a graph.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pylab, labeling points on a graph.
#1
def abs(absc, absx, c):
    # find zeros of the function
    zero1 = (absc + absx)
    if zero1<0:
        zero1 = (zero1*-1)
    input1=(zero1+c)
    input2=(zero1-c)
    # write zeros from smallest to largest and put into set notation
    inputs= []
    if input1 < input2:
        inputs = [input1, input2]
    if input1> input2:
        inputs = [input2, input1]
    # find the midpoint ant the two zeros on a number line.
    midpoint = (inputs[0]-inputs[1])*-1
    midpoint = (inputs[1] - midpoint/2)
    midpoint = int(midpoint)
    from pylab import plot, show, annotate
    mini, maxi = inputs[0], inputs[1]
    minix = str(inputs[0])
    plot(midpoint, 0, marker='o')
    plot(mini, 0, marker='o', label="-10")
    plot(maxi, 0, marker='o')
    y = [0,0]
    annotate("-10",(-10,0))
    annotate("10",(10,0))
    annotate("0", (0,0))
    plot(inputs, y)
    show()
    return inputs, midpoint
print(abs(-50, 50, 10))
[output([-10, 10], 0)][/output]

I am learning python and working with absolute value functions.
I am not able to post a picture. I wish I could because my question is about the figure. I was wondering if there is away to put labels on each of the three plots in my figure? The online document for plot says there is an option to add labels as long as it is string. I am not able to use it. I imported annotate. But that also requires string. I use str() function to turn the parts of my list into strings but it doesn't like my variables. The code runs "fine" but there are no labels. The only way I can put labels on is with annotate but I cannot use variables when I use the the annotate function. I have to hard code it every time. I'd like to use variables because then I can reuse the code for other problems and do not always have to update the labels for the points. Also if there is away to post a picture I'd be grateful to find out, Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding graph points and formating project_science 4 2,405 Jan-24-2021, 05:02 PM
Last Post: project_science
  Array problem in pylab module - Image processing bobfat 0 1,723 Dec-31-2019, 06:02 PM
Last Post: bobfat
  finding angle between three points on a 2d graph qrani 4 14,111 Nov-20-2018, 06:10 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020