Useful information for the research group
Python tips and tricks
Remove white lines in filled contour plots, pcolormesh plots, and colorbars
PDF output from Matplotlib often has little white lines separating patches in contour and pcolormesh plots, as well as colorbars. This will remove them from contour plots:
for c in cs.collections:
c.set_edgecolor('face')
This does the same thing for pcolormesh plots:
pc.set_edgecolor('face')
This does the same thing for colorbars:
cbar.solids.set_edgecolor('face')
cs, pc, and cbar are handles to the contour plot, pcolormesh plot, and colorbar objects.
Make figure background transparent while keeping axis backgrounds:
fig.patch.set_alpha(0.0)
Working with meta
Development environments
To activate various development environments, type the following at the bash prompt:
- Python 3.9: type
mamba activate latest
This will selection will only last as long as your login session. If you log out, you will need to reactive the desired environment.
Jupyter Lab
To run a Jupyter notebook server that will close when you close your terminal:
- Activate Python using conda activate
- Type
jupyter lab
- The notebook server will tell you
The Jupyter Notebook is running at: http://localhost:YYYY/
, where YYYY is your port number. - Open an SSH tunnel from your local machine to meta using the port YYYY. On Mac or Linux, this can be done by typing
ssh -L YYYY:localhost:YYYY meta.somas.stonybrook.edu
on your local machine. - Point your browser to
http://localhost:YYYY
. Your browser may warn you that the connection is not secure. Don’t worry about this and create a security exception for meta on your browser. - To shut down the notebook server, either close your terminal or type
Control-C
in the terminal window you used to start the server.
To run a Jupyter notebook server that will not close when you close your terminal:
- Activate Python using conda activate
- Type
nohup jupyter lab &
. ‘nohup’ tells the shell not to kill the server when you close the terminal. - The first line after you press enter will have the format
[#] XXXXX
, where # is a number and XXXXX is the process ID (PID) number. - The message telling you the server port will be at the bottom of the file
nohup.out
. You can display the last few lines of this file by typingtail nohup.out
. - Open a SSH tunnel and use your browser as described above.
- To shut down the notebook server, type
kill XXXXX
on the bash prompt. If you forgot your PID, useps
to list the PIDs of your running processes. After you kill the server, deletenohup.out
or else it will keep growing every time you restart the server.