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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:13:08+00:00 2026-05-17T02:13:08+00:00

Could you give me an example on how to use rgl to plot 3

  • 0

Could you give me an example on how to use rgl to plot 3 variables at the axes x, y and z and a fourth one with different colours?

thanks

  • 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-17T02:13:08+00:00Added an answer on May 17, 2026 at 2:13 am

    You use a combination of persp and colour according to a separate function. Here’s some example code:

    ## Create a simple surface  f(x,y) = -x^2 - y^2
    ## Colour the surface according to x^2 only
    nx = 31; ny = 31
    x = seq(-1, 1, length = nx)
    y = seq(-1, 1, length = ny)
    z = outer(x, y, function(x,y) -x^2  -y^2)
    ## Fourth dim
    z_col = outer(x, y, function(x,y) x^2)
    
    ## Average the values at the corner of each facet
    ## and scale to a value in [0, 1].  We will use this
    ## to select a gray for colouring the facet. 
    hgt = 0.25 * (z_col[-nx,-ny] + z_col[-1,-ny] + z_col[-nx,-1] + z_col[-1,-1])
    hgt = (hgt - min(hgt))/ (max(hgt) - min(hgt))
    
    ##  Plot the surface with the specified facet colours.
    persp(x, y, z, col = gray(1 - hgt))
    persp(x, y, z, col=cm.colors(32)[floor(31*hgt+1)], theta=-35, phi=10)
    

    This gives:

    Sample output

    RGL

    It’s fairly straightforward to use the above technique with the rgl library:

    library(rgl)
    ## Generate the data using the above commands
    ## New window
    open3d()
    
    ## clear scene:
    clear3d("all")
    
    ## setup env:
    bg3d(color="#887777")
    light3d()
    
    surface3d(x, y, z, color=cm.colors(32)[floor(31*hgt+1)], alpha=0.5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anyone give an example of why it would be advantageous to use MVC
Could someone please give an example of how to use ling to query over
Could someone give me an example of how to use the ContactPicker.PickSingleContactAsync() functionality correctly
Could you give an example where static_assert(...) ('C++11') would solve the problem in hand
Could anybody give an example to demonstrate the usage of the Invariant Culture ?
Could anyone give me example code to access the command line through VBScript? I
Could anyone give an example program that explains Java Threads in a simple way?
I was wondering if anyone could give me an example or point me to
Could anyone give me an example about how to do fuzzy matching of two
C#: Could anyone give me good example on how anchoring controls at runtime is

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.