Making Graphs

From TOI-Pedia


Expected Time: 30 min

In this tutorial you will learn how to create several graphs that can help you presenting your work. First we will focus on a type of graph related to a world map. After that, some methods for one-dimensional and two-dimensional graphs will be discussed.

World Map

Map of Brazil with hexagon pattern

Before you start with your Grasshopper script, please download the following Rhino file as your basis: Download Rhino World Map

Location pattern

Set a curve on the a parameter

In this chapter, we will create a hexagonal pattern for a specific country. First add a curve parameter to your canvas and set a specific country on the Grasshopper parameter. In our case, we selected Brazil.

  • Add a Curve Parameter to the canvas Params » Geometry » Curve
  • Set the Country Boundary on the curve parameter Select country boundary in Rhino » RMB on Grasshopper Curve parameter » Set one Curve

Create a surface from the curve

Create a surface from the boundary of the country.

  • Create a boundary surface Surface » Freeform » Boundary Surfaces

Evaluate the surface

Now we need to find the plane of the surface. This can be done by evaluating the box properties of the curve.

  • Find the plane of the Boundary Surface using the Evaluate Box Surface » Analysis » Evaluate Box
  • Set the U, V and W parameter to 0

Create a pattern on the surface

Add a pattern to the canvas. These patterns can be found in the Vector » Grid tab. In this tutorial, the hexagonal pattern is used.

  • Create a hexagonal pattern from the plane Vector » Grid » Hexagonal
  • Add Number Sliders to the Size, Extend X and Extend Y inputs to fill the surface Params » Input » Number Slider

Project the pattern on the surface

The hexagons will now be projected on the surface. Since the hexagons are created individually, the input of the projection needs to be flattened.

  • Project the Hexagon pattern on the surface Curve » Util » Project
  • Flatten the Curve input RMB on Curve input » Flatten

The result

As you can see, this created a hexagon pattern in the country region. Don't forget to turn off the preview of all the nodes you don't need.

Display a specific location of the grid

If you now want to get one specific hexagon, add a List item to the Hexagon Cells output. Make sure you flatten the data.

  • Connect a List Item to the Cells output SetList » List Item
  • Add a Number Slider to the Index input Params » Input » Number Slider
  • Flatten the List input of the List Item RMB on List input List Item » Flatten

Conclude the script with two curve parameters

To finalize your script, add two Curve parameters to the results, and change the name.

  • Add two Curve Parameters which hold the result Params » Geometry » Curve
  • Rename the Curve Parameters

Basic 1D Graph

Possible result of this chapter

In this chapter you will learn how to create a basic 1D graph. The data will be based on two random sets of numbers: the height and the volume of each point.

Create a range of numbers

First create a range of numbers, this will define the amount of data points in the graph.

  • Add a range component to the canvas Sets » Sequence » Range
  • Define the size of the range with a Number Slider Params » Input » Number Slider

Create a vector from the range

Now we construct a vector that holds the location of each point. For the Z-component, we use the random component. The amount of random numbers is equal to the amount of data points. Furthermore, we define a domain with the maximum and minimum possible value for the Z component.

  • Construct a vector using the range as X-component and a random node as Z-component Vector » Vector » Vector XYZ
  • Add a Random node for the Z-component input Sets » Sequence » Random
  • Define a domain with of the Random component Maths » Domain » Construct Domain

Represent the data points with spheres

Create a sphere that represents the data point. The radius is defined by a random number, again with a domain that defines the extremes. Use the same Number Slider for the amount of values.

  • Add a Sphere component to the canvas Surface » Primitive » Sphere
  • Define the radius of the sphere with a Random node Sets » Sequence » Random
  • Define the domain of the Random node with a Construct Domain node Maths » Domain » Construct Domain
  • Connect the Number slider of the Range node to the Number input of the Random node

Move the spheres to the correct location and calculate the volume

Now we move the spheres to the correct location using the move component. We also need the volume and centroid of each sphere.

  • Add a move component to the canvas. Use the created Vector XYZ as Motion input Transform » Euclidian » Move
  • Calculate the centroids with the Volume function Surface » Analysis » Volume

Add a gradient to the canvas

Add a gradient to the canvas. The color will represent the size of the spheres.

  • The gradient node can be found at Params » Input » Gradient

Select a colorscheme
  • Right-click on the gradient and select a preset you like. The color on the right will represent the maximum. The color on the left the minimum.

Sort and flatten the list of volumes

As you can see, the gradient asks for a Lower limit, Upper limit and Parameter. In our case, the lower limit can be left like this, because it already holds the value 0 (represents volume = 0). For the Upper limit we need the maximum. Sort the list of volumes and reverse it.

  • Sort the volume list Sets » List » Sort List
  • Reverse the Keys output LMB on Keys output » Reverse

Take the highest volume with the list item and set the upper limit

Use a list item to get the first (maximum) item from the list. Connect it to the upper limit. Connect the Volume output of the Volume component to the Parameter input of the gradient.

  • Find the first item with the list item component. Keep the Index input as it is. Sets » List » List Item
  • Connect the List Item output to the upper limit
  • Connect the original Volume output to the Parameter input

Create a polyline between the data points

A line between the points can be created by adding a polyline to the Centroid output of the Volume component.

  • Create a Polyline from the centroid output Curve » Spline » Polyline

Visualise the result

Now we need to display the Data Points. This can be achieved with the Custom Preview and material component. The diffuse input of the material will be based on the gradient.

  • Display the original geometry with the Custom Preview component Display » Preview » Custom Preview
  • Create a material for using the Gradient as Diffuse. Connect the material to the Material input Display » Preview » Create Material

Create an X-axis

If you want to make an x-axis with the values for each Data Point, construct a point from the original Range component we began the script wit. Using the Text Tag, you can display the values.

  • Construct points from the original Range component. Vector » Point » Construct Point
  • Visualize the x-components with the Text Tag. Use the created points as Location input Display » Dimensions » Text Tag
  • Connect the Range output to the Text input of the Text Tag

Basic 2D Graph

Result of this chapter

Here you will learn how to create a two-dimensional graph, based on two axes.

Create a Serie of numbers

Add a Series component to the canvas. This component will hold the values for the x-axis and the step size. Change the Count input to 12 and the Step input to 10.

  • Add a Series component to the canvas Sets » Sequence » Series
  • Change the Count input to 12
  • Change the Step input to 10

Create capped cylinders from the serie

Construct points from the created number sequence. After that, create a cylinder from each point. This cylinder geometries can be capped to make them closed.

  • Construct points from the Series. Use the Series output for the X coordinate input. Vector » Point » Construct Point
  • Create a cylinder with the point as Base input. Surface » Primitive » Cylinder
  • Cap the cylinders Surface » Util » Cap

Give the cylinders a random length

Create a range of random numbers for the y-values of the cylinders. The amount of numbers can be based on the length of the series component.

  • Define a random length with the Random component Sets » Sequence » Random
  • Use the length of the Series component for the Number input Sets » List » List Length

Write down the months in a text parameter

Add a text parameter to the canvas. By setting multiple texts, you can add all the months of the year.

  • Add a text parameter Params » Geometry » Text
  • Write down the names of the months in the Text parameter RMB on Text » Set Multiple Texts » Write down the names of the months

Display the names of the months

Create a Text tag with the original points as location input. By adding a XZ plane in between, the tags will be positioned in the right direction. Change the size and colour of the text to your wish.

  • Add a Text Tag to the canvas Display » Dimensions » Text Tag
  • Connect the Text Parameter to the Text input.
  • Add a XZ Plane between the Point output and the Location input Vector » Plane » XZ Plane

Additional Scripts

In the following downloadable zip-file, you will find some additional scripts that may be useful for your projects. Don't forget to Credit the Author.

Personal tools