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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:59:42+00:00 2026-05-29T23:59:42+00:00

I used matplotlib to create a scatter plot about fruits. Here is python algorithm.

  • 0

I used matplotlib to create a scatter plot about fruits. Here is python algorithm.

#
# Creat a scatter plot about fruits!
#

import numpy
import matplotlib.pyplot

# read refined results from TXT file
lines = []

with open("fruits.tsv", "r") as dataFile:
    lines = dataFile.readlines()

# remove line breaks
lines = [line.strip() for line in lines]

# break lines into tokens
tuples = [line.split("\t") for line in lines]

# remove the column names
titles = tuples.pop(0)

# make lists for each column
costs = [float(tuple[0]) for tuple in tuples]
calories = [int(tuple[1]) for tuple in tuples]
name = [tuple[2] for tuple in tuples]

plot = matplotlib.pyplot.scatter(costs, calories)
matplotlib.pyplot.title("Fruits by Cost and Calories")
matplotlib.pyplot.ylabel(titles[2])
matplotlib.pyplot.xlabel(titles[1])
matplotlib.pyplot.semilogy()
matplotlib.pyplot.grid(True, which='both')
matplotlib.pyplot.show()

And here is my tsv file.

Cost    Calories    Name
2.1 5   Apple   
1.4 4   Peach
4.1 2   Plum
3.6 1   Banana

(Yes, the data is a little outlandish.)
Why is name appearing on the y-axis, when I explicitly inputted cost for the y-axis?

To be clear, why is name on the y-axis when I inputted cost?
Fruit plot

  • 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-29T23:59:44+00:00Added an answer on May 29, 2026 at 11:59 pm

    Python lists are indexed starting from 0, not 1:

    >>> titles
    ['Cost', 'Calories', 'Name']
    >>> titles[0]
    'Cost'
    >>> titles[1]
    'Calories'
    >>> titles[2]
    'Name'
    

    Aside #1:

    lines = []
    

    isn’t needed. Remove it and see– it simply makes an empty list which is thrown away inside your “with”.

    Aside #2: tempting as it is, please don’t call your tuples tuple; that clobbers the built-in type. And they can be pretty handy for conversion purposes (for example, you used “float” and “int” here.)

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

Sidebar

Related Questions

I used the command below to create a 3D scatter plot: from mpl_toolkits.mplot3d import
I used matplotlib to create some plot, which depends on 8 variables. I would
In Python 2.6, I used matplotlib to make some simple graphs. However, it is
The current backend name is accessible via >>> import matplotlib.pyplot as plt >>> plt.get_backend()
I have used Matplotlib to plot lines on a figure. Now I would now
I recently decided to give matplotlib.pyplot a try, while having used gnuplot for scientific
I used the LINQ to SQL designer in Visual Studio to create an object
When used like this: import static com.showboy.Myclass; public class Anotherclass{} what's the difference between
We used to use SourceSafe, and one thing I liked about it was that
I am having trouble installing matplotlib on mac os 10.6, so I used macports

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.