Show more

@jakub_neruda I could watch it all day too - it calms you down, somehow!

Here’s a “from-the-archives” post

I’ve been recently having more and more conversations – some privately and some publicly – on using the turtle module for more than just drawing circles and patterns!

Some of you may know this is one of my favourite topics – in this example, we’re using it to visualise how sines and cosines are linked to the motion in a circle

How many children (and adults) learn about sines and cosines but don’t know what they really are?

thepythoncodingbook.com/2022/0

Are you comfortable with the difference between positional arguments and keyword (or named) arguments when calling a Python function?

And which order to use them in?

Here’s the second article in the Intermediate Python Function series, hot off the press, so to speak

thepythoncodingbook.com/2022/1

Everything in #Python has a type... even things you might not expect to have a type.

Like None

>>> type(None)
<class 'NoneType'>

Or NotImplemented

>>> type(NotImplemented)
<class 'NotImplementedType'>

Or... type?

>>> type(type)
<class 'type'>

@s_gruppetta I find it very nice, it's replaced a lot of the crufty matplotlib boilerplate I've accumulated over the years for creating publication-ready figures. You can always drop back down to "raw" matplotlib if you need to do something very specific.

@jford I’ve not used proplot before, may have a look at it at some point!

I’ll be mostly posting about in the data analysis and science and related domains here…

…but for those learning to code, whatever the final aim, it’s good to get a broad perspective

So here’s something different to learn about or consolidate the key data structures in Python - lists, tuples, dictionaries, and sets

Here’s the link to the article for those who want a “diversion” from more serious-looking exercises!

thepythoncodingbook.com/2021/1

@freemo @trinsec @peterdrake should clarify that my instance is QOTO, but I hesitate to use markdown in my posts as many will not see the text formatted properly. So I often opt for plain text with markdown symbols

@freemo @trinsec @peterdrake I see! It’s a shame that the raw markdown is not passed on to non-markdown servers

@trinsec @freemo @peterdrake Also, non-QOTO users will see this as plain text (without the markdown characters) - it would be ideal if they say the markdown rather than plain text

@BustaMarx If I can be a bit self-serving, I can offer The Python Coding Book – it’s written as a friendly, relaxed, yet thorough approach for beginner-to-intermediate learning

thepythoncodingbook.com

I think a good way to show code (until we wait for all servers to have Markdown like , at least) is to show a generated code image (from one of several online tools, or screenshot if you must) and add the code as the ALT text/description of the image, as in the quoted toot.

If, as in this case, the code is too long for the ALT text (this will only happen for long code snippets like this) the code could go in an unlisted reply to the toot with the image (or in the same toot, if you prefer/have space)

I think it’s useful to have both a properly-formatted version for those who just want to read code and text which people can copy-paste

gist and other solutions means you need to leave the site - not ideal, I think

Stephen Gruppetta  
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

We are doing an episode on "Mastodon for #Python (and open source) devs".

We'll be live streaming it on Monday.

youtube.com/watch?v=LhBfMoR3bv

Hope you can join @mkennedy, @foosel, @simon, and @astrojuanlu

Well, the code was too long for the ALT text, so here's the code pasted here:

import matplotlib.pyplot as plt

image = plt.imread("gardens.jpeg")

# Create a figure using a 4x4 array.
# The "." indicates an empty space in the grid
fig, ax = plt.subplot_mosaic(
[["Colour", "Colour", "Colour", "Hist Red"],
["Colour", "Colour", "Colour", "Hist Green"],
["Colour", "Colour", "Colour", "Hist Blue"],
["Red", "Green", "Blue", "."]]
)

ax["Colour"].imshow(image)
ax["Colour"].axis("off")

# Plot histograms for red, green, and blue channels
ax["Hist Red"].hist(image[:, :, 0].ravel(), bins=50, color="red")
ax["Hist Red"].axis("off")
ax["Hist Green"].hist(image[:, :, 1].ravel(), bins=50, color="green")
ax["Hist Green"].axis("off")
ax["Hist Blue"].hist(image[:, :, 2].ravel(), bins=50, color="blue")
ax["Hist Blue"].axis("off")

# Extract red, green, and blue channels from image
image_red = image.copy()
image_red[:, :, 1:] = 0
image_green = image.copy()
image_green[:, :, 0] = 0
image_green[:, :, 2] = 0
image_blue = image.copy()
image_blue[:, :, :2] = 0

ax["Red"].imshow(image_red)
ax["Red"].axis("off")

ax["Green"].imshow(image_green)
ax["Green"].axis("off")

ax["Blue"].imshow(image_blue)
ax["Blue"].axis("off")

fig.show()

Show thread

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

Show thread

Have you used subplot_mosaic() in ’s 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

@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!

@2mamili Thank you! I’m glad you’ve enjoyed it and found it useful

It’s designed and written to be a friendly and relaxed approach to learning and while still being thorough, of course.

Let me plug it here by putting the link for anyone else in an early or intermediate stage of learning , especially those going down some sort of data analysis or scientific programming route:

thepythoncodingbook.com

Show more
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.