Visualizing data is one of the most useful skills, you can detect trends, changes, correlation, clusters and several attributes in the data by just looking at it. Although there are several packages that can generate data visualizations, blender offers a high-performance platform for 3D graphics. And with its scripting capabilities creates a huge amount of opportunities in terms of visualization. In the following post, I will show you how to create a simple script to generate a simple bar plot in Blender.
The input data needed for this script to work is the bar height, the bar labels, and the “Y” axis ticks. However, it works only for 9 or fewer bars.
First, we remove the starting cube and relocate the camera to the final position.Then we create a new mesh with the location at the origin of the plane and change the scale of the mesh. And finally, we add a wireframe modifier to that mesh. That will result in a grid for the background of the plot.
Once we have the background we can add the bars. First, we calculate the length of the bar bases on the scale that we have. Then we relocate the bar according to the global coordinates. And then we locate that bar evenly spaced across the grid.
Now that we have the bars we can add the names of each bar. First, we create a new text object just below the bar location and we enter edit mode. Then we delete four times the content of the object. That will remove the default “Text” in the object. Then we iterate through each character in the label to write the label. And finally, we exit edit mode.
With the labels in the position we just rotate the labels and apply some scaling to make it to an appropriate size.
A similar approach is used for the labels in the “Y” axis.
As we have all the elements in the scene, we can start to add some style to the plot. First, we change the horizon color in the scene. Then we can add some material to each item in the plot. We create a new material, then we change the color and finally we apply that material to the object.
And as a result, we get the following plot. The full script can be found in my git hub by clicking here. See you in the next one.