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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:41:27+00:00 2026-06-10T14:41:27+00:00

I would like to draw a 3D carpet plot with Python Pylab or matplotlib.

  • 0

I would like to draw a 3D carpet plot with Python Pylab or matplotlib. I explain what I mean with carpet plot:

I have points on a X,Y meshgrid. This points have an elevation attached to them, but also an integer from a finite set. A common 3D plot makes it possible to vizualize relief. Elevation is along Z, we can vizualize elevation for a points determined by its coordinates X,Y along Z-axis. Alternatively, I draw heatmaps for elevation. It is a 2D plot, each pixel determined by X,Y has a color that is a function of altitude, red for apex and blue for bottom. I do some clustering on these data, and after clustering, I have, for each pixel, two information: elevation and a label (integer). I can draw a 2D map with each pixel colored with its label, and this gives me the clustering results.

Now, I would like to plot both information on same 3D graph. Z coordinate should be elevation, and the point on surface should be colored with its “cluster color”. This is what I call the 3D carpet plot (if term does not sound correct, please tell me).

  • 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-10T14:41:29+00:00Added an answer on June 10, 2026 at 2:41 pm

    Your “cluster color” is some set of conditions on the X,Y,Z values of your grid. If you can make these a mask (of True/False values) it is simple to map a color onto them. I’ve given an example of an arbitrary set of conditions, which you can adapt to your needs. Code was adapted from http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/tutorial.html:

    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    import numpy as np
    
    # Some sample data
    x_side = np.arange(-5, 5, 0.04)
    y_side = np.arange(-5, 5, 0.04)
    X, Y = np.meshgrid(x_side,y_side)
    
    # Fake mountains
    Z = np.exp(-(X**2+Y**2)) + 2*np.exp(-((X-2)**2+Y**2)) 
    
    # Assign colors based off some user-defined condition
    COLORS = np.empty(X.shape, dtype=str)
    COLORS[:,:] = 'b'
    COLORS[(Z>.1) * (Z<.3)] = 'r'
    COLORS[Z>.3] = 'g'
    COLORS[X+Y < -1] = 'k'
    
    # 3D surface plot
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    surf = ax.plot_surface(X, Y, Z, facecolors=COLORS, rstride=1, cstride=1,
            linewidth=0)
    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

We have an array of points through which we would like to draw a
In C# i have a picturebox. i would like to draw 4 colors. The
I have to design a GUI using Qt. I would like to draw multiple
I would like to draw diagrams and charts and have the following restrictions: -
I have 3d mesh and I would like to draw each face a 2d
I am new to CSS and would like to draw a border around this:
I have 2 CGPoints and a would like to draw straight line between them,
all I follow this http://msdn.microsoft.com/en-us/library/ka0yazs1.aspx to create an application and would like to draw
I have a dataset with about 50 points (x,y) and I would like to
I have a problem: I would like to draw a grey overlay on an

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.