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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:14:58+00:00 2026-05-28T13:14:58+00:00

I am new to using matplotlib. I am trying to create a 2D grid,

  • 0

I am new to using matplotlib. I am trying to create a 2D grid, using matplotlib. This is my first time using matplotlib for anything non trivial.

I have decided to break the task into 3 parts:

  1. Create the grid table (shown below), color the appropriate columns, and label the axis correctly. This is the one I need most help with. My initial idea is to hold the data for the table in a list of dictionaries (or list of lists); the data struct could hold some meta data about which columns were colored, and then I could simply create the matplot plot off of that data – but I haven’t really done any plotting with matplotlib and could do with some help in getting started.

  2. Plot a symbol (say ‘X’) in a grid cell with coordinates (row,col)

  3. Save the grid table as a picture (this one is easy, I can do by myself)

Here is a picture of the kind of grid table I am looking to create using matplotlib:

matplotlib grid table

I will be very grateful for any help that gets me started.

PS: the image is not rendering very well. The horizontal lines in the table are all the same weight (i.e. thickness), so the visual effect of the grid table should look like an Excel worksheet.

[[Edit/Update]]

Just to clarify, what I’m trying to create is a kind of ‘chess like’ game board. I have managed to modify the code snippet Ricardo posted in his answer, to get as close as I can (with my limited matplotlib skills!) to this game board as I can. However, there are a couple of things “missing”:

  1. The x axis column labels are strings, not numbers, they are string labels e.g. AB1, AB2, AB3 etc. Additionally, these labels are midpoints (i.e. they are centered, or lie BETWEEN the x axis ticks – not on the ticks themselves)

  2. I need to be write symbols in a particular column for a given y axis value, for example, I may want to write the text ‘foo’ at y axis value -1565.5 in column ‘AB2’.

Once I have this, I am sure I will be able to hack something together to get to the game I am trying to write – especially, since I have just bought a copy of Matplotlib for Python developers.

  • 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-28T13:14:59+00:00Added an answer on May 28, 2026 at 1:14 pm

    Mmh… I guess you could achieve this by asking matplotlib to show the grid, and combining a barplot (to color the columns) with a scatter plot or direct text drawing, for the symbol(s)

    Edit: This may help you getting started. Needs some work on the ticks, though.

    #!/usr/bin/python
    
    from pylab import *
    import matplotlib
    import matplotlib.ticker as ticker
    
    # Setting minor ticker size to 0, globally.
    # Useful for our example, but may not be what
    # you want, always
    matplotlib.rcParams['xtick.minor.size'] = 0
    
    # Create a figure with just one subplot.
    # 111 means "1 row, 1 column, 1st subplot"
    fig = figure()
    ax = fig.add_subplot(111)
    # Set both X and Y limits so that matplotlib
    # don't determine it's own limits using the data
    ax.set_xlim(0, 800)
    
    # Fixes the major ticks to the places we want (one every hundred units)
    # and removes the labels for the majors: we're not using them!
    ax.xaxis.set_major_locator(ticker.FixedLocator(range(0, 801, 100)))
    ax.xaxis.set_major_formatter(ticker.NullFormatter())
    # Add minor tickers AND labels for them
    ax.xaxis.set_minor_locator(ticker.AutoMinorLocator(n=2))
    ax.xaxis.set_minor_formatter(ticker.FixedFormatter(['AB%d' % x for x in range(1, 9)]))
    
    ax.set_ylim(-2000,6500, auto = False)
    # And set the grid!
    ax.grid(True, linestyle='-')
    
    # common attributes for the bar plots
    bcommon = dict(
        height = [8500],  # Height = 6500 - (-2000)
        bottom = -2000,   # Where to put the bottom of the plot (in Y)
        width = 100)      # This is the width of each bar, itself
                          # determined by the distance between X ticks
    
    # Now, we create one separate bar plot pear colored column
    # Each bar is a rectangle specified by its bottom left corner
    # (left and bottom parameters), a width and a height. Also, in
    # your case, the color. Three of those parameters are fixed: height,
    # bottom and width; and we set them in the "bcommon" dictionary.
    # So, we call bar with those two parameters, plus an expansion of
    # the dictionary.
    
    # Note that both "left" and "height" are lists, not single values.
    # That's because each barplot could (potentially) have a number of
    # bars, each one with a left starting point, along with its height.
    # In this case, there's only one pair left-height per barplot.
    bars = [[600, 'blue'],
            [700, 'orange']]
    for left, clr in bars:
        bar([left], color=clr, **bcommon)
    
    show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe this is a very silly question but I'm new using django. I have
I still very new using Subversion. Is it possible to have a working copy
When creating a new project using zf create project myproject it will create a
Im new using Python, now I have a problem using ElementTree and read out
I am very new to Python and I have been trying to detect missing
I have been using mplot3d (part of matplotlib) for some various 3d plotting, and
I am new using spring 3 and have been stuck for a while on
I want to mention that I'm new using sql developer and I'm trying to
Ok, I'm new using this connect by thing. But its always quite useful. I
Sorry, I am still new using jquery so this might be an easy question.

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.