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

  • Home
  • SEARCH
  • 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

C#: Could anyone give me good example on how anchoring controls at runtime is
Could someone give some info regarding the different character sets within visual studio's project
Could any one give an explanation on how a DHT works? Nothing too heavy,
Could you, please, give a code snippet showing how to use Lua embedded in
I was wondering if anyone could give me an example or point me to
Could somebody give me a brief overview of the differences between HTTP 1.0 and
Could you give some guidance for good resources (books, online tutorials) about embedded assembly
Without spending a long time reviewing the boost source code, could someone give me
Could anyone could point me to some code/give me ideas on how to create
Currently I use a single equation with different combination of known/unknown parameters. As I

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.