-1

So I wondered how matplotlib (or equivalents) makes graphics appear on your screen.

I found that matplotlib does not do the drawing itself; instead it is built on TKinter, which is built on TK, which is...and the rabbit hole/stack continues.

Is the software package/library/code at the bottom of this stack achieving this by just interfacing with the operating system via assembly code to manipulate pixels on the screen?

  • read wikipedia about [windowing systems](https://en.wikipedia.org/wiki/Windowing_system). You could read thousands of pages related to [X window system](https://en.wikipedia.org/wiki/X_Window_System) or [Wayland](https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)) on Linux, and both are [open source software](https://en.wikipedia.org/wiki/Open-source_software) (whose source code you are allowed to study; that will take you years of work); see e.g. [this](https://www.x.org/releases/X11R7.6/doc/man/man3/) – Basile Starynkevitch Jul 30 '21 at 19:19
  • In practice, your graphics card can draw lines and probably polygons with specialized hardware (the [GPU](https://en.wikipedia.org/wiki/Graphics_processing_unit)) - executing a specialized set of instructions – Basile Starynkevitch Jul 30 '21 at 19:24
  • @BasileStarynkevitch Thanks - I understand this is probably quite an open-ended question. Essentially I wondered where/at what level the piece of code that draws that line/pixel/whatever resides. For example, I tried looking through matplotlib's lib/ but of course couldn't find it. – armoured-moose Jul 30 '21 at 19:25
  • How many months of work (or years) full time can you afford spending in learning that.... I have about ten thousand printed pages related to X11, and some documentation is missing. Read more about [OpenGL](https://en.wikipedia.org/wiki/OpenGL) – Basile Starynkevitch Jul 30 '21 at 19:29
  • [this documentation](http://developer.amd.com/wordpress/media/2013/12/AMD_GCN3_Instruction_Set_Architecture_rev1.1.pdf) is giving the instruction set of an old (2013 - 2016) AMD graphics card, and your CPU will download to your GPU specialized graphics "programs" to draw – Basile Starynkevitch Jul 30 '21 at 19:55
  • And to add confusion, they very well might not even draw to the screen, I would expect they draw to a bitmap in memory independent of any screens, so it likely doesn't involve the OS or GPU at all except the very last single step. – whatsisname Jul 31 '21 at 00:35

1 Answers1

2

This is indeed a very open-ended question, and it sadly shows little previous research efforts.

I would say at this level of previous knowledge it suffices to say that ultimately, pixels are just memory locations that can be accessed using ordinary read and write operations in any language that allows memory access. There are different possible ways pixel data is organized in memory, but for simplicity you may assume that each pixel could be represented as a three-byte element of red, green and blue intensities in an array of width*height size.

The graphics libraries (and often the associated hardware) knows how to translate x/y coordinates into array indices, how pixel values are combined when pixels shouldn't be fully overwritten for transparency or anti-aliasing etc. But at the end of the day, it's just array elements being read and written.

In many cases, there are additional copying steps involved. For example, a graph drawing library might write pixels into ordinary main memory, and the window system and graphics driver copy these to screen memory.

Whether the high-level code is matplotlib, a text processor, or some game, doesn't really matter.

Hans-Martin Mosner
  • 14,638
  • 1
  • 27
  • 35