Data Visualization in Blender and Python
HTML-код
- Опубликовано: 15 окт 2024
- In this tutorial we'll create a script that reads data from CSV files(comma separate values) and converts it into a list of data that we can use to generate a bar graph. No prior python experience is needed to follow along, but I don't go over every aspect of the fundamentals of programming, so some experience would really help in understanding everything.
You can download the resource files for this tutorial here - cgmasters.com/...
Check out cgmasters.com for more courses and tutorials.
Like the tutorial and want to leave a tip?
PayPal - www.paypal.me/...
Bitcoin - bc1qh2cx8kz4wjj855cruk2sfwftl69vmmuau94w9v
Ethereum - 0xfb2D6886347434Eb2DACde22C6b96889dDAE6255
XRP - r4A4bxQ5wK8R1rEhecgvTy1wSXoCfoE42b
Dogecoin - DLDZ8fngi4KJkNnHQafV4vxDwaPzZ7e92W
This is easily one of the better python scripting tutorials I've found.
Thank you for teaching.
One of the best sets of instructions and explanations I have seen yet. Simple and straightforward without being overwhelming. Bravo! You have gained a subscriber.
This is cool, I would be happy to see more scripting in Blender tutorials.
RUclips compression seems to really struggle with that dark pinkish-red over dark grey color that those python commands have, even in full screen 1080 they aren't very clear.
Yeah I noticed that after uploaded, and that was disappointing, but lesson learned. For the next tutorial I'll make sure to adjust the background color so the text pops more. Thanks for the feedback! -Chris
Instead of doing readout.index(a), it is actually faster to do:
for i,a in enumerate(readout):
...
This is because the index() method requires an additional linear search, so your program loops over the same data twice. This has a time complexity of O(n²).
While enumerate just keeps track of the current location as you are doing the first loop, which is O(n) (smaller is better).
thank you so much for this turorial i used it for a different project that also required me to access data from a csv file and you explained everything so well you helped me more than 4 hours in blender forums did.
Awesome. I think that's a promising feature of Blender for creating wonderful infographics.
Scripting is something I've been willing to do for a long time so thanks for this amazing tutorial ! And cuz you ask, yep I would love some more videos on that topic 😁 thanks and keep up the good work !
Thank you very much! I learned tones of knowledge about blender in just 15 minutes (I speed up the video by 2x).
really really excellent tutorial
tip: to automatically delete all objects before executing the code you can add this after import csv and import bpy
for o in bpy.context.scene.objects:
o.select_set(True)
bpy.ops.object.delete()
Oh good stuff, I didn't think about that. Very handy for testing and re-testing, thanks for the code. -Chris
Great tutorial easy to follow and to understand with great info. Please make more. Good JOB!!!!!!!!!!!!!!!!!!!!!!!!!!!
This is exactly what I'm looking for! Wow thanks for making this. Once again Blender gets the job done when all or software have failed me.
im dissapointed the first thing you did was not deleting the cube :D great video thanks a lot
32:45 Pro tip: A faster way to see a list of all the properties of the selected object is to just go to the python console and type bpy.context.object.data. (with the trailing period) and hit the tab button, which will show you a much nicer, cleaner list of all the properties, without needing to run your code to do it.
Ah awesome, thanks for the tip!
What a great high-quality Python tutorial!
Thank you!👍
SO well taught... I'm a total cabbage when it comes to code.... and I have issues with logic in code... In other words I don't code because I'm pretty crap at it. But this guy was very clear in his descriptions. Well done. If I understood that...then a lump of swamp mud with a small sense of awareness... will grasp it. It's all in the teaching... and I know he was doing this pretty fast... so if he had time I'm sure this would be comprehensive in its explanations. Nice.
This is a great introduction to python in blender, thanks for the video!
THIS. IS. GREAT! Thank you Chris! Hope all is well!
Hey Jimmy! Yep all is well here, hope it is there too =)
Hey bud! All good here in Covid-Ville. This is madness lol. So, I have one question. I understand the values in the CSV precipitation data equals the amount on grid space it rises on Y axis, my question is how can I alter that graph Y value to let's say, half that? I'm not sure how this works as I am python Challenged. No worries if you can't get into it. This is a great thing though. Thanks again for doing this! Be well and stay safe!
Disregard! Thanks to watching your explanation AGAIN I actually learned something! Got it!!! Thank you sir!
@@Drums712 haha glad you figured it out! And no problem =D
Amazing, easy to understand. perfect for beginners. thank you
Absolutely fabulous presentation!! Kudos!
So cool, very well done.
Thank you and THANK YOU!!! This is was an amazing lesson dear friend, that helps me to go further to python language.
such an awesome tutorial, I have also joined the blender encyclopedia course on udemy and its really awesome.
Thanks Kriti! And I'm happy to hear you're liking the encyclopedia =)
if you're on Linux and can't see a toggle system console button, just run blender from the terminal and you can observe all console output there in the terminal
Great tutorial! About radians, is quite normal use them for trigonometrics calculation.
Thanks! And oh yeah, I just wanted to include that general note about radians so no one is too confused on why they can't just specify a degree amount in that line. -Chris
Really helpful and sweet for the brain !
Thank you for the awesome tutorial! I am also curious about how to make the axis and grids.
I'll likely make a second part to this soon to generate the grid, camera placement, and automatically apply materials. -Chris
Great tutorial, are you planning on more, maybe doing stuff with pandas and numpy for more complex data sets?
I probably won't get any more complex than this when it comes to the data involved. I would like to finish this tutorial though and automate the rest of the graphics, like shaders, rounded top, background, etc, but not sure when this will happen.
Nice Tutorial ! Very nicely Explained! 😍😍
Thank you so much for this tutorial, I had a lot of fun following along and then implementing some extra functions, like the materials, a camera pointed at the center of the graph or the axis lines. For some reason though right-clicking the info panel doesn't show any menu so I can't copy paste from there, any idea why this can be?
Ah that's weird and I'm not sure why that would happen. Maybe it's an operating system difference? What OS are you on?
Thanks Chris. This is a great video.
I feel this is essential for understanding animation nodes, am i right Chris? Anyway do you know anything about the development of everything nodes? what exactly is that?
I've never actually used animation nodes, and not sure what these mysterious everything nodes refer to either haha, but they sound awesome.
@@blengine hahaha okk.. i thought you know everything..😜
@@SansVirus-dz3bi I'm going to need about 100 more years to learn every single area of Blender. Then maybe another decade for all the add-ons too haha.
We need to animate this chart in next tutorial
This will likely happen. I'm anxious to finish this script now with one or two more parts. I want to generate the background grid in the next part, then in the second part we'll generate an animation where the background grid constructs itself, then each bar stretches tall one by one. Not sure when I'll get to these though, there's a lot I had plans for, but I'll tinker around with this stuff this week.
@@blengine For bar chart i have written the script for the animations. its done and working good.
Now trying to write script which applies materials to each bar based on its value.
XS that was really cool and what would be cool is to learn how rotate and move an image on a mesh but in a fashion of equation on a twirling in helix that gets smaller and smaller in the center yet the image move on the helix. Both will move in the way of the procedural equation for the nautilus. 292 ! nodes
Thanks for a super cool video, my first time using Blender, it's cool to see one's own script make a graph.
add "* bar_width" to the transform on the text, like this;
bpy.ops.transform.translate(value=(placement * bar_spacing * bar_width + 0.5, -0.5, 0))
@chris would love to see a way to use blender to create visual models of multiple dimensions - almost like a stack of graphs on x & y axes that show how data clusters across multiple dimensions.
This tutorial basically maxed out my knowledge on this data viz stuff, but I know there are a lot of other data viz tutorials and I think there's even some free add-ons floating around for 3d visualization as well.
amazing tutorial, i'm 10 minutes in as of writing this comment, and i would like to ask: the "readout" variable created within the context of the "with" code block, was read in the "for loop" context and was used to create the 12 planes accordingly, this is odd behavior to me as i would guess the act of clearing the identation would erase a reference to variables created within that identation's context, is this commom with the "with" keyword?
i haven't finished the python manual, i have been going back and forth with blender and python to master scripting within blender
I hope I understand you right. Are you asking why we're able to get information from the "readout" variable into the FOR loop even though that variable is not inside the FOR loop? The script is processed from top to bottom and variables are remembered along the way. So as long as the variable is defined and processed previously in the script, then later parts of the script can reference it. It's important that the variable is processed first though. For example, if the first line of the script is a simple statement like "if 1 == 0: readout = 5", well the IF statement is false so the readout variable is never processed and can't be referenced later in the script.
BTW Chris - will there be car modeling course, updated to 2.8x?
Yeah but I'm not sure exactly when. It probably won't be out until next year though. -Chris
Very awesome, thank you !!!
This is when you are 3D Modeller but at the same time you're also Data Analyst
I am curious as to why you moved the planes in the same way you would in edit mode (leaving the origins on the cursor), but moved the text like you would in object mode (which carried the origins with the text).
Is there a particular reason you did this? I was replicating this for my own Bar Graph script and started out using bpy.ops.transform.translate before I had realized I'd deviated.
For the planes I wanted to keep the origin at the bottom left of the entire graph. That way I could scale away from the origin to make the bars wider or slimmer. For the text, they aren't ever being scaled, nor did they have vertices, so I just moved them as objects to make sure they stayed centered under each bar.
In retrospect though, for the plane's width I'm sure this could've been done another way. Like in the script I could've specified scaling the planes away from the 3d cursor instead of the origin, and it could've achieved the same thing as scaling away from the origin which is at the cursor anyway. Then we wouldn't have had to move the vertices one by one with the FOR loop. But that makes me wonder which way would be more efficient when it's actually executed. Either way it's a tiny script though so efficiency isn't as crucial.
@@blengine That is kind of what I had assumed. Thank you for the response! This video was really well done!
heyyy, testing in my computer i had to change the rotate value to bpy.ops.transform.rotate(value=-1.56)
I have just enlisted on your course Blender 2.8 Encyclopedia on Udemy. As a beginner is it enough to start only with it?
Yeah I am using it to and I were a complete beginner. I would recommend to supply what you have learned by making some projects on your own as well while watching the course.
Yep that course is suited for any skill level, including total beginners. Just make sure to check out the Navigating the Course lecture at the beginning as well, there's a few tips on how the course is outlined that may help you learn better from it. -Chris
Hi Chris, is this tutorial in the blender encyclopedia udemy course?
No this one's not in there. Eventually we'll work on a scripting section for that course(possibly a separate volume) but we haven't gotten around to that quite yet.
@@blengine Excellent, btw thanks for the course, It has been very useful for me
Thanks a lot for your video! I have to subscribe to your channel now!
placement = readout.index.(a) is a line of code that I wonder if I will ever be able to understand. : Readout is from the CSV file and it does not indicate a placement value in blender.
Oh "placement" is a variable that you can name anything you want. I just named it placement because it's being used to place the bars.. So we look for "a" in the Readout list, and whatever position "a" is in the Readout list is the number assigned to the "placement" variable. I hope that makes sense.
Please make more on scripting...I got the blender encyclopedia!
I hope to work with scripting more in 2021!
Amazing, thanks!
I changed distance between bars, and I have distance between texts in 2 times longer than between bars. What do I wrong?
Hey, been a while since I did any python or anything with this tutorial, but if you send your blend file to me at chris.cgmasters@gmail.com I might be able to figure it out.
@@blengine hey! I found that it happened when I make bars' widths 0.5 instead 1. But it's not a big deal, don't worry. Will you make a video with animation in Python?
@@ОстапБендер-б9д I don't think I'll be making any other python videos, coding is not something I'm that experienced with at the moment.
What version of blender is this?
I think this was 2.83.
Really nice.
Koniu to film dla Ciebie :D
Lovely
Hi Chris. What a strange word parentheses ... The python script which creates everything like in Finished_Graph.blend example. May be it'll help somebody.
Wow that script looks extensive! It doesn't seem to generate perfectly though, leaving the grid overlapping the bars, text overlapping the bars too, and not rounded off because there was an error on line 289, no attribute 'affect'. I didn't look too closely at the script to fix it all because this is something I think I'll continue and finish like you've done, and I'd like to take a stab at finishing things without getting ideas from another script, and then take things further and automate an animation of the whole thing constructing itself. Seeing all your functions has me interested in better organization and optimization of my own script though haha. Thanks for this, after I take a stab at this myself I'd love to look through this and compare, because I likely won't automate the materials unless it's easier than I think it'll be so that's something I'd like to check out in yours. -Chris
@@blengine It looks like you are using blender 2.83.x version. The script works fine in 2.9. As a developer I always use latest version and forgot to test it in 2.83.x. Sorry for that. That's why it fails on line 289. The developers have changed python API on a new bevel modifier again.
To make it working with 2.83.x there are few changes should be made.
1. replace the line 289
#mod.affect = 'VERTICES'
with
mod.use_only_vertices = True
2. There is a bug with opposite rotation in 2.9.
I fixed it analyzing blender version
bpy.ops.transform.rotate(value=math.radians(+-90), orient_axis='Z')
3. Overlapping issue could be easily fixed by moving overlapping areas a little bit down along z axis. I think its better solution rather than taking into a count line thickness.
Updated version which works in 2.8 and 2.9 drive.google.com/file/d/1QWEWUMY93p7UWobpQVjDUbHN-lCPC0T8/view?usp=sharing
@@max_nadolny Ah works perfectly! I should've known and tested it in 2.9 before. Amazing work, this is awesome. And good to know about the changes in 2.9 as well, when I continue this tutorial series I'll need to be careful with that.
@@blengine Thank you Chris! Nice to hear good feedback from you.
Do I need to download CSV addon for this?
Nope, that's actually what the tutorial is all about, we write a python script to read CSV data.
@@blengine Is it possible to use 3d-geometry rather than bars? This is same you can create easily in Microsoft Excel
@@kraphik3d Yeah it's possible. One simple way is to add in cubes instead of planes. I don't have any tutorials on this though so I couldn't tell you exactly what to do, but with Python you can create much more complex results than shown in this tutorial.
Is this going to be in the blender encyclopedia also?
I don't think I'll include this in the encyclopedia until we actually go to create the full scripting section for it. Otherwise this would be random for that course since it has no primer or fundamentals lectures for scripting yet. -Chris
@@blengine Nice, i'll be waiting for the course.. Thanks Chris.
You could update this using Geometry nodes
how to do with 3d data?
Is it hard to learn in Linux.
I used linux for about a year before when working at the blender institute, and I found it to be easy enough to learn and get comfortable with so I don't think you'll have a problem if you're thinking of trying it out. I don't know a whole lot about it though, like if there's a lot of software compatibility issues or things like that, but I imagine at this point it's developed enough to be a smoother experience than when I used it many many years ago.
@@blengine It took me a while to figure out how to get absolute filenames to work automatically in code. But now the code works as it should. Actually, it was quite easy in the end. As long as you found the right guide. Thank you for a good guide.
thanks for sharing, couldn't' you just grab each plane instead of each vertex of each plane?
Nice way to read csv file and put it in a python list, I will use it 😉
for exact radians, "from maths imp radians" , and rotate from radians(90)
@@totochandelier Hey Tony, yeah I didn't think it through, but initially wanted to keep the origins in their original position to be easier to scale from later for bar widths. I could have moved them as objects though and then just set the script to scale from the cursor and could have achieved the same results without a For loop. Though it makes me wonder which is faster? It seems like moving the object would have to update the origin and the vertex values when the scripts exectured, whereas moving the vertices alone just needs to update the vertex values. Not that efficiency really matters with a small script like this, but I'm curious. And originally I had the radians code in the script, but it wasn't really necessary to be that precise, so I erased it for a more concise script. -Chris
@@blengine don t know if it has an effect on rendering , but these small scripts run very fast as far as pure animation is concerned.
concerning barycenters, seems to work with me
ruclips.net/video/AuLNPFZIVNM/видео.html
@@totochandelier Very cool, creative way to get those bards to materialize too.
migraine kicking in 4 3 2
Migraine - hello, Juju....
File "C:\Users\...\Desktop\Bar_Graph_Resource_Files\untitled.blend\GraphGenerator", line 3
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
location: :-1
did you use forward slashes as the video instructed?
Don't forget to switch your back slashes to forward slashes. Also double check that the file path includes the actual file name you're opening as well. -Chris
now, make an addon of it :D
haha, yeah this could definitely be taken a lot further and be a decent add-on for customizable data viz. -Chris
This isn't programming. Wow. Comma separated values. I can see if you're streaming real-time over the serial port.
Using blender to make histograms? Does not make any sense to me. Was looking for something which is Blender-worthy.
Damn but Excel aint free
I have made an add-on for this, if you want to check it out there is a video with links on my youtube channel!
Oh yeah I tweeted about that a while back! Amazing looking plug-in, great work on that. -Chris
@@blengine There is a new update for it! Video is coming next week!
blender is alive because of addons without addons it is just like somewhat upgraded skecthup for modelling
Nah blender would still be amazing without add-ons and is far more feature filled than sketchup. Add-ons enhance it greatly still, and I hope a lot of the good ones out there become integrated eventually. -Chris
@@blengine imagine blender without hardops and boxcutter
@@arko3822 They're certainly great for efficiency with certain kinds of modeling, but Blender's modeling tool set is still amazing.
@@blengine it's extrude manifold is broken ....I have to get an addon called destructive extrude to fix it....to replace the looptool and polybuild tool I have to use polyquit addon.....It's selection tool is limited so I have to use box select x-ray addon...If they would have been amazing people would not have been complaining about tools in blender on right click select ....and people were not buying addons of 38 dollars if it would have been that awesome.....compare modo's modelling toolkit with blender...u will see the difference
@@blengine If the movement tools were that awesome nobody would have needed the CAD transform addon.....and pivot transform addon for positioning pivot and snap utils ...instead of blender knife tool
What is you instagram id....i want to tag you in a corvette post😁
cgmastersnet I think, I don't really use the instagram account much these days. -Chris
@@blengine okay.....so where should i show you?.... cause i am really excited to show it to you😂
@@deepakchouhan3372 Do you have a portfolio on artstation? That's a great place to post artwork. I'll see it on instagram too though.
@@blengine unfortunately not😔
a couple weeks ago I was looking for this exact same thing 😙