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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:53:12+00:00 2026-05-24T18:53:12+00:00

I am trying to create a plot in matplotlib where the x-values are integers

  • 0

I am trying to create a plot in matplotlib where the x-values are integers and the y-values are strings. Is it possible to plot data of this type in matplotlib? I examined the documentation and the gallery for matplotlib and could not find any examples of this type.

I have many lists bound to a variable called my_lists. The structure looks like this:

mylists = [765340, 765371, 765310,'MA011',],
          [65310, 'MA015'],
          [765422, 765422, 24920205, 24920161, 'MA125'],
          [765422, 'MA105'], 
          [765371, 12345, 'MA004']

In each list, all items except the last item are x-values. The last item in each list is a string, which is the single y-value.
How can I plot this is matplotlib? Here was my attempt:

import matplotlib.pyplot as plt

for sub_list in my_lists:
    x_value = sub_list[:1]
    y_value = sub_list[-1]
    plt.plot(x_value, y_value, "ro")
    plt.show()

The above code throws me this error:

ValueError: could not convert string to float: MA011

How can integers versus strings be plotted?

  • 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-24T18:53:14+00:00Added an answer on May 24, 2026 at 6:53 pm

    You could probably do something like this, where you give each y “string” a unique index value. You may have to fiddle with the spacing for i. Ie. i*2 instead of i to make things look nice. After that you set the tick label for each of those indexes to its corresponding string.

    import matplotlib.pyplot as plt
    
    fig = plt.figure(figsize=(9,7))
    ax1 = fig.add_subplot(111)
    
    
    mylists = [[765340, 765371, 765310,'MA011',], [65310, 'MA015'], 
               [765422, 765422, 24920205, 24920161, 'MA125'],
               [765422, 'MA105'],[765371, 12345, 'MA004']]
    
    x = []
    y = []
    y_labels = []
    y_ticks = []
    for i,sub_list in enumerate(mylists):
        y_labels.append(sub_list[-1])
        y_ticks.append(i)
        for v in sub_list[:-1]:
            x.append(v)
            y.append(i)
    
    ax1.set_yticks(y_ticks)
    ax1.set_yticklabels(y_labels)
    ax1.plot(x, y, "ro")
    plt.show()
    

    EDIT:

    Sorry I forgot to include the enuemrate call in the for loop. It basically sets the value of i to the index of the current sub_list. Then you use the index instead of the string value as the y-value. After that you replace the label for those y-values with the actual string value.

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

Sidebar

Related Questions

I'm trying to create a Matplotlib animation of my paw data, where you can
Trying to create a list to return some JSON data to a view. Following
I'm trying to create a ggplot2 plot with the legend beneath the plot. The
I am trying to create a Google Map where the user can plot the
I'm trying to create a procedure which extracts data from a MySQL server (using
I am trying to plot a bunch of data points (many thousands) in Python
I am trying the create a loop to extract data from an array created
As question, I am trying to create a plot using the following code: chart.demo.sex.age
I'm trying to create a pdf of a TukeyHSD post hoc test plot (through
I'm trying to create a plot using pyplot that has a discontinuous x-axis. The

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.