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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:26:56+00:00 2026-05-23T06:26:56+00:00

How do you obtain graphic primitives and directives from a Graphics object? Leonid Shifrin

  • 0

How do you obtain graphic primitives and directives from a Graphics object? Leonid Shifrin showed how to remove them in the post Mathematica: Removing graphics primitives. I tried applying something similar but I can’t get what I want. Consider this example:

 g1 = ListPlot3D[
    {{0, -1, 0}, {0, 1, 0}, {-1, 0, 1}, {1, 0, 1}, {-1, 1, 1}},
    Mesh -> {2, 2},
    Boxed -> False,
    Axes -> False,
    ViewPoint -> {2, -2, 1},
    ViewVertical -> {0, 0, 1},
    MeshStyle -> RGBColor[0, 0.5, 0],
    BoundaryStyle -> RGBColor[1, 0.5, 0]
 ];
 g2 = ImportString[ExportString[g1, "PDF", Background -> None], "PDF"][[1]]

output

g2 is now a graphics object. If you look at the InputForm of g2 you will see that this graphics object is composed of Polygons and JoinedCurves. What I would like to do is able to iterate through all of the primitive objects of g2. If we try to iterate as follows

 objs = First[g2];
 Table[Head[objs[[i]]], {i, 1, Length@objs}]

we obtain

 {Thickness, Polygon, Polygon, Polygon, Polygon, Style, Style, Style, Style, 
  Style, Style, Style, Style, Style, Style, Style, Style, Style, Style, Style, 
  Style, Style, Style, Style, Style, Style, Style, Style, Style, Style, Style, 
  Style, Style, Style, Style, Style, Style, Style, Style, Style, Style, Style, 
  Style, Style, Style}

What I would like to obtain instead is a list of simple primitives, I do not want them inside Styles. Here is one attempt obtaining only the lines and colors:

 tmp1 = Cases[objs, (_JoinedCurve | _RGBColor), Infinity];
 tmp2 = DeleteCases[objs, (_Polygon | _Thickness), Infinity];
 GraphicsRow[{Graphics[tmp1], Graphics[tmp2]}]

output

Notice that the image on the left is drawn incorrectly. This image was generated using only JoinedCurves and RGBColors. It somehow managed to miss one color, that is why we have a black line and then the rest of lines have the other color. The other image is drawn correctly, all we did was delete all the Polygons and Thickness that appeared in there. What am I doing differently here? Shouldn’t we obtain the same plots?

  • 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-23T06:26:57+00:00Added an answer on May 23, 2026 at 6:26 am

    I read:

    What I would like to obtain instead is
    a list of simple primitives, I do not
    want them inside Styles.

    You can get it just by simple replacement:

    First[ g2 /. Style[expr_, opts___] :> {opts, expr} ]
    

    Now you write:

    Here is one attempt obtaining only the
    lines and colors

    Knowing the internal structure of g2 it is simple to extract only Line objects with its colors. It is even simpler because all Lines are wrapped with Style:

    tmp3 = Cases[g2, 
       Style[{lines__Line}, ___, color_RGBColor, ___] :> {color, lines}, 
       Infinity];
    Graphics[tmp3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I obtain an array of byte (byte[]) from db and render into a Image
How obtain the running process with absolute path name from ps command 13598 ?
currently i obtain the below result from the following C# line of code when
I want to obtain last links from specific user account. I use this code:
I would like to obtain a list of files from a git repository that
How can I obtain a string of the Bundle Identifier programmatically from within my
I'm trying to obtain the price from a field called DiscountMarkupPriceRate1 on my second
Is it possible to obtain ServletContext from MyPortlet extends MVCPortlet in Liferay? I know
Is it possible to change the options of a Graphics object? Say you are
How do I obtain the endpointIdentity from the config file?

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.