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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:42:20+00:00 2026-06-03T17:42:20+00:00

To add a rectangle to my plot I usually use this code: ret=Rectangle((x_l[i]-dx,y_l[i]-dx),width=dx,height=dx,facecolor=’red’,linestyle=’solid’) ax=gca()

  • 0

To add a rectangle to my plot I usually use this code:

ret=Rectangle((x_l[i]-dx,y_l[i]-dx),width=dx,height=dx,facecolor='red',linestyle='solid')
ax=gca()
ax.add_patch(ret)

However I was wondering if was possible to give the color in a different way. I want my rectangle to be colored according to a colorbar. I’ll try explain it better. Every rectangle represent a cell and in every cell I define a scalar field. My scalar field ranges from min_val to max_val. I want every rectangle that I drawn to be color that correspond to the value of the scalar field in the rectangle.

  • 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-03T17:42:26+00:00Added an answer on June 3, 2026 at 5:42 pm

    You can draw every Rectangle with the color calculated by ColorMap:

    import matplotlib.colorbar as cbar
    import pylab as pl
    import numpy as np
    
    N = 50
    xs = np.random.randint(0, 100, N)
    ys = np.random.randint(0, 100, N)
    ws = np.random.randint(10, 20, N)
    hs = np.random.randint(10, 20, N)
    vs = np.random.randn(N)
    normal = pl.Normalize(vs.min(), vs.max())
    colors = pl.cm.jet(normal(vs))
    
    ax = pl.subplot(111)
    for x,y,w,h,c in zip(xs,ys,ws,hs,colors):
        rect = pl.Rectangle((x,y),w,h,color=c)
        ax.add_patch(rect)
    
    cax, _ = cbar.make_axes(ax) 
    cb2 = cbar.ColorbarBase(cax, cmap=pl.cm.jet,norm=normal) 
    
    ax.set_xlim(0,120)
    ax.set_ylim(0,120)
    pl.show()
    

    enter image description here

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

Sidebar

Related Questions

How can I use emacs string-insert-rectangle operation to add a vector of numbers to
Displaying a rectangle and binding Width, Height, Angle to a view model class works
What happens behind, when i add a rectangle Rectangle{ width:40 heigh: 40 color:blue }
I want to add textblock or label inside rectangle which is creating with code
User can give id, width, height and description rectangle and then I write it
I want to get a .jpg on a canvas, add a rectangle and a
To add a whitespace seperator in a string we use String.Join(). My question:What(and how)
I add my page top link button like this: <a name=top></a> . . .
I add many check boxes to the excel sheet programaticaly using the following code:
Maybe someone know how to solve this problem: I Have XY Plot with points

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.