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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:09:24+00:00 2026-06-07T17:09:24+00:00

I am trying to create a barb vector plot in matplotlib and map some

  • 0

I am trying to create a barb vector plot in matplotlib and map some colors to specific magnitudes: for example, to have vectors with magnitudes between 10 and 20 plotted as blue, and between 20 and 30 as rgb(0,15,40), and so on. The documentation for the barbs and quiver functions (they are similar) mentions the C input arg:


barb(X, Y, U, V, C, **kw)

Arguments:

X, Y:
The x and y coordinates of the barb locations (default is head of barb; see pivot kwarg)

U, V:
Give the x and y components of the barb shaft

C:
An optional array used to map colors to the barbs


However, this is very vague, and after searching all over Google, I am no closer to understanding how to use this color array in specific ways. I managed to discover that by setting C equal to the array of vector magnitudes and specifying the “cmap” kwarg, it will map the barbs to the specified colormap, as in the example code below. However, this is not what I want. I want to control the colors of specific groups of magnitudes. Any help would be appreciated.

Example code:

from matplotlib import pyplot as plt
from numpy import arange,meshgrid,sqrt

u,v = arange(-50,51,10),arange(-50,51,10)
u,v = meshgrid(u,v)
x,y = u,v
C = sqrt(u**2 + v**2)
plt.barbs(x,y,u,v,C,cmap=plt.cm.jet)
plt.show()

Resulting plot image link: (sorry can’t post images directly yet)

http://i49.tinypic.com/xombmc.jpg

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

    You can get it by discretizing the map.

    import matplotlib as mpl 
    import pyplot as plt
    from numpy import arange,meshgrid,sqrt
    
    u,v = arange(-50,51,10),arange(-50,51,10)
    u,v = meshgrid(u,v)
    x,y = u,v
    C = sqrt(u**2 + v**2)
    cmap=plt.cm.jet
    bounds = [10, 20, 40, 60]
    norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
    img=plt.barbs(x,y,u,v,C,cmap=cmap,norm=norm)
    plt.colorbar(img, cmap=cmap, norm=norm, boundaries=bounds, ticks=bounds)
    plt.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

hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I'm trying to create a simple form with sonata bundle. I have one problem
I am trying create a 'live' view where our clients can edit the colors
Trying to create a pattern that matches an opening bracket and gets everything between
I am trying create a data.frame from which to create a graph. I have
Trying to create an app that does some socket communication (Writing only). I can
I'm trying create new object from a module class in VBA, and I have
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5

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.