Here’s the code for the plot in the previous post - put in your own image file, of course!
You can get the text from the images’s ALT text
Have you used subplot_mosaic()
in #Python’s #Matplotlib yet?
Or are you a dinosaur like me and still use older functions? After all, subplot_mosaic()
was only introduced in 2020 in version 3.3
Recently, I decided to finally explore subplot_mosaic()
and I know I’ll never go back to whatever I did before to plot these types of figures!
/1
#coding #programming #Visualisation #LearnPython #LearnToCode
@s_gruppetta your python coding book ist the best I ever read about coding ! Thank 🙏🏼you so much 🙏🏼for the free version online. So many things I finally understand - you did an amazing job!
Since moving from #MATLAB to #Python all those years ago, I had used meshgrid()
the “non-ideal” way for so long–it was just habit from many years of using it in MATLAB
But now I know better, and my memory usage will be happy in so many cases!!
If you’ve come to #Python directly from #MATLAB, as I have, and you used to use meshgrid
in MATLAB, you possibly use it in exactly the same way in Python?
I did for a very long time…
But Python has more options which can save you execution time and memory
Here’s my exploration of #NumPy’s #meshgrid and other related functions
https://thepythoncodingbook.com/2022/05/28/numpy-meshgrid/
#programming #coding #LearnPython #LearnToCode #ScientificProgramming #Visualisation
#introduction
I'm Mariatta, in Vancouver 🇨🇦
I work at Google as Senior Developer Relations Engineer, maintaining open source Python client libraries for Google Cloud.
As one of the #Python core developers, I care about documentation, workflow, bots, and contributor experience.
I'm the Chair of #PyConUS 2023-2024, Fellow member of @ThePSF and Community Service Award recipient.
My pets are a variety of tropical freshwater fish and some Amano shrimps.
I love food, traveling, and kdrama 👋
Hi there,
#introduction
This is the official Mastodon account for the Python Software Foundation (PSF.) We're the non-profit home of the Python programming language and our mission is to to promote, protect, and advance the Python programming language, and to support and facilitate the growth of a diverse and international community of Python programmers.
We also run PyCon US, https://us.pycon.org/2023/
We're excited to be here. :D
Hi new followers. We just got @talkpython officially on Mastodon. Please follow if you're interested in the show.
Hi #Python people. Made it to FOSS Mastodon. Please connect if you like the podcast.
…time to get inspiration for some other #FourierOptics #Python tutorials to follow on from this, which remains the most popular post on the blog, by far
My favourite textbook of all time – had been in storage for a while as we did a long, convoluted, house move…
It’s back, safe and sound, nicely weathered and thumbed from all those years of use…
PS: just realised it’s my wife’s copy, not mine. I Want My One Back! (It’s still in a box, somewhere…)
#Python #Fourier #FourierTransform #FourierOptics #programming
@s_gruppetta This kind of dynamic 3D plotting is very useful for illustrating physics concepts like your example here, but in business applications it's indeed much less common and, in general, not necessary (at least in my company). But the fact that it's not used all over the place only enhances the coolness of this example 😉 I will certainly enjoy this!
@s_gruppetta this is really awesome! Given that it's for learning the coding side, I won't mark you down for using explicit integration 😜.
It's amazing how dynamic visualization can really solidify complex topics. Even when I've done iterative static computation in the past, dynamically-updating matplotlib plots really helped give me more intuition about the problem I was trying to solve.
@s_gruppetta @mborus We’ll update this server (ETA unknown) to import some of the useful features from the main branch (vanilla Mastodon). An edit button is one of those. :)
@freemo Is there a reason why toots using markdown do not appear as raw markdown for those on servers who don’t support markdown and instead appear as plain text with all the markdown ignored?
It makes it tricky to decide whether to use markdown, or to use plain text and put the markdown symbols as plain text so everyone gets the same version
Some are confused about the terms “mutable” and “immutable” in #Python or #programming in general.
A Toot could be a good example but it seems that this is not the same for everyone (in the process of changing?)
For me, at the moment, a Toot is “immutable” –> Once it’s published, it cannot be changed. I can delete it and replace it with a new one, but I cannot change the actual Toot
But for others (and from what I gather, for all of us in the near future?), a Toot is “mutable” if they can change the same toot, not just replace it with a new one
Let’s say you have a string, an immutable type in Python:
name = "Stephen"
You change your mind and want it to be upper case:
name = name.upper()
You’re creating a copy of the string which is uppercase and replacing the old string (which is binned) with the new one
That’s not the case for a list, for example, which is mutable:
numbers = [2, 5, 9]
numbers.append(100)
You change the same list, not create a new one
Will Toots change from being an immutable type to a mutable type for all of us soon?
…but he won’t stay there long. Monty finds the name print
in the built-in red booklet which gives him directions to the print
Function Room which is elsewhere in Python City.
He’ll leave the Main Room to go to the print
Function Room, taking the integer 13
with him.
When Monty finishes from the print
Function Room, he’ll return to the Main Room and carry on with whatever instructions come next.
Usual caveat: analogies are not perfect. So don’t take them literally. Literally!
But, our brains react better to narratives rather than random facts. So I find that these ‘stories’ help me understand and remember this stuff so much better…
Hopefully it will help others, too.
If you want to read more on this analogy, you can read this:
https://thepythoncodingbook.com/understanding-programming-the-white-room/
/6
However, if the function call was just:
do_something_clever(5, 8)
then Monty doesn’t know what to do with the data he’s holding. So he’ll throw it away in the garbage bin so he can carry on with his work.
What if you write:
print(do_something_clever(5, 8))
Monty will go to the do_something_clever
Function Room, do what he needs to do, and return to the Main Room holding the integer 13
…
/5
However, he won’t go empty handed. He’ll take some data with him—the arguments you use when you call the function.
In the example in the previous tweet, Monty will take the integers 5
and 8
when he goes from the Main Room to the Function Room.
As Monty enters the Function Room, he’ll find two empty boxes at the entrance labelled first
and second
— these are the parameters from the function definition.
He’ll place the integer 5
inside the box labelled first
and the integer 8
in the box labelled second
. He will then place these boxes on the Function Room shelves.
Monty will then do whatever he needs to do in the Function Room.
When he’s done, he’ll return to the Main Room.
But once again, he won’t return empty-handed. He’ll take the contents of the box labelled output
with him since this is what you wrote in the return
statement.
Note that Monty does _not_ take the whole box labelled output
with him but only its contents. In the example above, this is the integer 13
What will Monty do with this integer as he returns to the Main Room and shuts the Function Room door behind him?
If the function was called like this:
result = do_something_clever(5, 8)
then he’ll bring another empty cardboard box, place the integer 13
inside it, and label the box result
. He places this box on the shelves in the Main Room.
/4
Anyway, let’s get to defining a function:
def do_something_clever(first, second):
"""do some stuff"""
output = first + second
return output
A function is a mini-program within a program.
So, in my mental image of how computer programming works, a function is another room…
When you define a function, you’re creating a new Function Room that’s adjacent to the Main Room.
There’s a door connecting the Main Room to the Function Room.
The label on the door says do_something_clever
, the name of the function.
So, when you use the name do_something_clever
, Monty will look around the Main Room and see the name as a label on a door leading to another room.
If you’ve called the function by adding parentheses, do_something_clever(5, 8)
, Monty will open the Function Room door and go through it.
/3
• Rethinking how to teach programming – I prefer the friendly, relaxed approach when communicating about Python programming
• I write about Python on The Python Coding Book blog and on Real Python
• Former Physicist
• Expect posts on scientific and numerical programming –> NumPy, Matplotlib and friends!