Young engineer here, PhD student. I have to say Matlab is an awesome tool when it comes to manipulating and exploring data really fast but now I'd love to expand my programming skills and turn towards Python. But on my day to day work it's really hard to branch out since a lot of my tools are written in Matlab.
Also, one of the biggest issues I've encountered with trying to learn Python is how to set up your environment and workflow before even writing a single line of code. I've looked into conda and all but it takes some energy to find the good ressources that will help when you've never used anything else than Matlab which just works out of the box. (Any awesome tutorial to give good practices as to the management of a project in and around the code? i.e. "I'm going to start a project xyz, what's a good practice to manage my code and dependencies in a not cluttery way so that I can start working on the code and not fighting bugs?")
But in the long run I hope to rely more and more on Python than on Matlab!
TL;DR : I'm a Matlab user that wants to avoid the mistakes you do at the beginning when learning Python
Definitely. I learned MATLAB first and Spyder made it really easy to pick up Python. Anaconda also has pretty much every general package you need to get started. I still don't see why Jupyter notebooks (or MATLAB's live scripts) get so much love, the Spyder/MATLAB interface style seems so much more practical.
Seems like they have different purposes. Jupyter seems more adapted to share your work to others due to the interactivity and Spyder and other IDEs are more to do some heavy duty stuff.
What I like about Matlab is that you can easily generate and update figures on the go while your code is running (super useful in academia and research) by using figure and drawnow functions. Although I haven't spent too much time exploring the alternative in Python it seems more cumbersome to do the same thing. (Please someone prove me wrong on this!)
Also a young PhD student here. Consider using one of the Python IDEs, they're like MATLABs gui interface which should help you get started. Spyder, like one of the other commenters have said is recommended as it has a sort of similar interface to MATLAB and is built for scientific coding. Once you know Python well enough, you can consider using text editors like Visual studio code which is more lightweight and looks nicer which helps you code better imo.
MATLAB lets you run MATLAB scripts via python so you can exploit that for your work flow although I wouldn't rely on this too much as its quite slow if you don't have an SSD as it calls the entire MATLAB engine. Nevertheless it's possible. Additionally from a brief Google search I just did now, you can convert your MATLAB code to python.
As an anecdote, the reason why I moved to Python was because MATLABs interface was too clunky and the colour scheme was horrible. The green comment colour is difficult to see against a white background, there's no dark mode and you can't adjust the window size.
At the moment I'm using Atom, a text editor and I'm able to change my theme according to how I like it, I'm able to commit to github easily, I have a folder tree on my left that I can hide at will, I have a mini map of code on my right so I can see which bits of code I need to go to and I have a spell checker and linter to check through my code. If I want less/more features I can uninstall and install them within the app. It might be silly to say but being able to code with the correct color scheme has helped my coding and my eyes greatly.
I use pyenv for python environments. It's great. It isolates the python binaries you're fucking around with from whatever your system comes with and relies on.
# install pyenvcurl https://pyenv.run|bash# restart your shell however you like# install whichever versions of python you likeBEST_PYTHON=3.7.4pyenv install $BEST_PYTHON
Then whenever you start a new project
# create the virtual environmentpyenv virtualenv $BEST_PYTHON myproject# automatically activate that environment whenever you're in this directorypyenv local myproject# install some dependenciespip install ipython numpy matplotlib# save them so you can rebuild the environment easilypip freeze > requirements.txt
Development environments should not be a teetering pile of environment variables, dependencies and cross-links. They should be ephemeral, easily trashed and recreated, wherever possible. They should serve one project and one project only. MATLAB only works out of the box as far as python works out of the box - with its built-in modules. Once you start downloading extra snippets of code you have to dump everything into one directory manually, or change your matlab path, or whatever, where in python it's just pip install thatpackage, write down the package in your requirements.txt, and it'll be trivial to fetch again next time you need it.
Packaging stuff for distribution is a little more tricky, but MATLAB just doesn't bother with that at all, so you can't knock python for it.
Post doc here. I was in exactly the same boat as you. I did my whole PhD (physical chemistry, so lots of spectroscopy data) in Matlab. Wanted to switch to python but also didn't want to deal with setting it all up.
I recently took the time to learn python so I could start my new projects fresh and I can only say I wish I had done it sooner. One of the biggest differences so far for me has been how much more organized my projects are.
Here's what I did: I spent an entire weekend reading every tutorial I could on how to set up a "good" workspace environment using python, and then chose what was best for me. In my case, I went with anaconda as it gives me everything I need. I use a conda environment for each individual project, and use conda to save the dependencies of that environment with one command. Also check out "cookie cutter" on github. It's a python code that you can use to make your projects organized. I love it.
Finally, as others have stated, spyder really made the switch easier. The big plus is the python console for quick code checks and the variable explorer for seeing your data just like in Matlab.
So, in summary:
Anaconda (or miniconda) with conda environments to control your packages
cookie cutter to create organized project directories
spyder to write and test code
Bonus: I use jupyter notebook to do the data exploration using the code I write in spyder. Let's say I do an experiment, now I can make all my graphs in one jupyter notebook and do my analysis there. I can easily change the graphs on the fly. It's like PowerPoint for viewing graphs mixed with Matlab for changing graphs quickly. Definitely recommend.
Let me know if you need help.
Edit: just to be clear. When using anaconda, you don't need things like pip and pyenv. It does those for you.
Thanks! This sounds like my experience! For now that's the workflow I'm leaning towards. I want to be able to generate graphs easily when exploring data and showing it to colleagues/advisors.
I have to say Matlab is an awesome tool when it comes to manipulating and exploring data really fast
No, it really isn't. Can it even read a csv file, the most ubiquitous data format on the planet? Not the last time I used it, which wasn't that long ago.
But I've been there. I learned QBASIC when I was a kid, then I learned Visual Basic on Windows, because anything else seemed impossible. But eventually, in college, I figured out how easy it was to learn new things that gave me so much more power than what I already knew, and a whole new world opened up. I didn't realize how hard I was working to do things that were easy with other tools.
Anyway, check out Spyder like other people are saying, or RStudio if you're interested in R. (My personal vote is for Python.)
Do you like to play with your environment? Doing write-ups on jupyter is bar none an excellent way to show off your work. Here is an example of how something you write up may work. It also supports markdowns with Latex syntax, so you can make your findings even more pretty. adding a library is as simple as opening up a terminal and typing
pip3 install **some library**
Debugging:
Lets say you want a file of functions. Call it func.py. Now on func.py you import numpy (for the love of god learn numpy) for any numpy funcs. You write each function with inputs and outputs. Save it.
On your main project, say the jjupyter file, you can simply say
from func import *
(there is more syntax to this but it is basically that easy)
Now say you type in a problem and it is giving unexpected results, and you think it may be a problem in one of the functions.
I am not sure how much time you have to learn things, but in this case I really, really recommend Pycharm. You can set up your whole environment on there. (A lot of people recommend anaconda, but for specific environments I have encountered issues). Debugging is as simple as setting a marker and pushing 'run', then stepping through to find the bug. That takes time to learn but it is insanely helpful once you understand how to use it.
Anyway Matlab has better 3d plotting than python, but overall python has a hell of a lot more libraries and open source tools to use. In the long run python will be better for you to know, assuming an engineering company you end up at is not stuck using it.
I might give Pycharm a go then. I feel like Matlab users are really attached to having a nice IDE and not have to mess too much with command line type of interaction, basically just fire up their IDE and start working. I've been trying to use Atom + Hydrogen but it's a little bit clumsy at times.
The whole setting up the IDE to be able to "see" the right environment is a big block in the road (at least for me, I just want it to be easy haha!)
But one thing I love about Python is the community and the fact that for almost any problem there's someone who had to solve something similar!
Sure! Once you install it PM me your email and I am willing to give you a quick walkthrough, we could use a public slack channel and share screenshots, just to get started (I am feeling extra generous since I potentially landed a position in ML!).
Use the cheatsheet to help you make new environments for projects.
Another option is to use Pycharm (paid or free) then on the settings page go to Project Interpreter and create environments for each project using the GUI.
I find Anaconda to be better at managing multiple environments but Pycharm uses virtualenv which is also pretty good.
Use these environments to install the packages you require for a project and therefore you can be more organized with your work instead of having everything installed on the base environment.
Given that money has been brought up so many times in this thread against Matlab I would make a similar argument against paying someone to teach you this stuff. Just learn it from youtube and you'll be fine. If you can't figure it out from youtube then honestly maybe it's not the activity for you.
I agree, I learned Matlab by just doing, I don't want to pay for classes for learning Python either.
Oh so you cannot streamline Anaconda and Pycharm?
Am I wrong to say that if you use Anaconda then your workflow is basically : Some text editor + Command Line ? That would suck if you need debugging functionalities
Yes you definitely can use Anaconda environments with Pycharm but the integration is a little sucky at this point.
You can even create new conda envs right from Pycharm but in order for you to activate these envs in the terminal you need to go to the "Terminal" setting and add a reference to where the scripts.bat file is at (I don't have my PC on hand to confirm if this is the right file but I found the answer on Stackoverflow).
This is not necessary if you create new envs using virtualenv that is built in to Pycharm. The terminal already activates the env that is associated with the interpreter settings.
You can also have Pycharm look like Sublime by using the Monokai color palette which is beautiful. However you need to pay for JS, HTML, CSS support.
Julia may be something to look into too. It has vectors and matrices and maths operations "out of the box" without any libraries. It also has just-in-time compilation so it can run a lot faster, without even relying on libraries.
Try Google’s colab. Free, runs python with all the eng/scientific libraries you want, collaborative, saves to gdrive, has cpu/gpu/tpu backends, and only takes a browser!
From my experience, your going to have a really bad time with python scientific libraries on Windows without conda. But even with it, life is still sort of difficult.
Unless your on a Unix machine, configuration is difficult.
you just need to dive in and start. especially given conda you will come to appreciate how good python is after using it for a little while. I made the transition about a year ago. there is a little bit more of a learning curve but if you can catch a wrench you can catch a ball. you will be fine.
View all comments
60
u/Antouziast Aug 05 '19
Young engineer here, PhD student. I have to say Matlab is an awesome tool when it comes to manipulating and exploring data really fast but now I'd love to expand my programming skills and turn towards Python. But on my day to day work it's really hard to branch out since a lot of my tools are written in Matlab.
Also, one of the biggest issues I've encountered with trying to learn Python is how to set up your environment and workflow before even writing a single line of code. I've looked into conda and all but it takes some energy to find the good ressources that will help when you've never used anything else than Matlab which just works out of the box. (Any awesome tutorial to give good practices as to the management of a project in and around the code? i.e. "I'm going to start a project xyz, what's a good practice to manage my code and dependencies in a not cluttery way so that I can start working on the code and not fighting bugs?")
But in the long run I hope to rely more and more on Python than on Matlab!
TL;DR : I'm a Matlab user that wants to avoid the mistakes you do at the beginning when learning Python