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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:04:01+00:00 2026-06-17T09:04:01+00:00

I have some 3D data e.g. d=[x, y, z, f] where z is a

  • 0

I have some 3D data e.g. d=[x, y, z, f]
where z is a column of numbers in Z, used as color information.

f is a flag which is

  1. 0 if x and y have some specific values (ugly^^)
  2. 1 if x and y are ok

So for the good data d[ d[:,3] == 1 ] I want to generate a profile

plt.imshow(resampled.T, extent=extent, vmin=MIN, vmax=MAX, origin='lower')

and for the ugly data d[ d[:,3] == 0 ] I want to just use a specific color, e.g. black

Is there a way to realize that?

EDIT: Combining the comments of @eumiro and @Rutger Kassies, I have now the following result
enter image description here

Which is satisfying I think.
For the sake of completeness (or maybe there are some optimization I’m not aware of^^), here is the code and the data:

import numpy as np
from matplotlib.mlab import griddata
import matplotlib
import matplotlib.pyplot as plt


def plotprofile(x, y, z0, name='dummy', save=1):
    #plt.figure()
    N = 50j
    z = z0[:,0]
    extent = (min(x), max(x), min(y), max(y))
    xs,ys = np.mgrid[extent[0]:extent[1]:N, extent[2]:extent[3]:N]
    resampled = griddata(x, y, z, xs, ys)

    cmap = plt.get_cmap()
    cmap.set_bad(color = 'k', alpha = 1.)
    #plt.imshow(resampled.T, cmap='Greys', extent=extent, origin='lower', interpolation='spline36')
    plt.imshow(resampled.T,  cmap=cmap, extent=extent, origin='lower',  vmin=min(z),  vmax=-min(z),interpolation='spline36')

cbar=plt.colorbar()
s=20
plt.ylabel(r"$y$", size=s)
plt.xlabel(r"$x", size=s)
plt.xlim([x.min(),x.max()])
plt.ylim([y.min(),y.max()])

if save:
    for end in ["pdf", "png", "eps"]:
        print "save %s.%s"%(name,end)
        plt.savefig("%s.%s"%(name,end))
else:
    plt.show()
plt.clf()


if __name__ == '__main__':
    filename = 'data.txt'
    data = np.loadtxt(filename)
    x = data[:,0]
    y = data[:,1]
    z = data[:,3:]
    plotprofile(x, y, z,  'dummy', 0)
  • 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-17T09:04:02+00:00Added an answer on June 17, 2026 at 9:04 am

    Can’t you create just a normal colourmap in z by using f to mask z?

    dd = d[:, :3]
    dd[:,2] = dd[:,2] * d[:,3]
    

    Then convert to an image like this:

    M = dd.max(0)
    m = dd.min(0)
    
    x = np.arange(m[0], M[0] + 1)
    y = np.arange(m[1], M[1] + 1)
    [X, Y] = np.meshgrid(x, y)
    
    Z = np.zeros_like(X)
    
    for num in range(0,size(dd, 0)):
        Z[dd[num, 0], dd[num, 1]] = dd[num, 2]
    

    Now you should be able to plot Z like a normal image or as a surface against [X, Y]

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

Sidebar

Related Questions

I have to sort out my data by some column, such that some specific
I have some data which is stored in a VARCHAR(MAX) column that contains the
I have some data that I am displaying in 3 column format, of the
I have some data that is stored in a TIMESTAMP(6) WITH TIMEZONE column in
I have some data in an SQL table with an XML datatype column where
I have some data that looks something like this... +----------+----------+----------+ | Column 1 |
I need to get some data from a column. For example I have data
I have a data frame with an id column and some (potentially many) columns
I have a datatable with data in it (customer addresses). In some instances, column
Hey guys, I have an application that I want to display some data from

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.