Posts with #matplotlib

How to create custom tables
Introduction This tutorial will teach you how to create custom tables in Matplotlib, which are extremely flexible in terms of the design and layout. You’ll hopefully see that the code is very straightforward! In fact, the main methods we will be using are ax.text() and ax.plot(). I want to give a lot of credit to Todd Whitehead who has created these types of tables for various Basketball teams and players. His approach to tables is nothing short of fantastic due to the simplicity in design and how he manages to effectively communicate data to his audience.
Art from UNC BIOL222
As part of the University of North Carolina BIOL222 class, Dr. Catherine Kehl asked her students to “use matplotlib.pyplot to make art.” BIOL222 is Introduction to Programming, aimed at students with no programming background. The emphasis is on practical, hands-on active learning. The students completed the assignment with festive enthusiasm around Halloween. Here are some great examples: Harris Davis showed an affinity for pumpkins, opting to go 3D! # get library for 3d plotting from mpl_toolkits.
Newly released open access book
It’s my great pleasure to announce that I’ve finished my book on matplotlib and it is now freely available at while sources for the book are hosted at Abstract The Python scientific visualisation landscape is huge. It is composed of a myriad of tools, ranging from the most versatile and widely used down to the more specialised and confidential. Some of these tools are community based while others are developed by companies.
Battery Charts - Visualise usage rates & more
Introduction I have been creating common visualisations like scatter plots, bar charts, beeswarms etc. for a while and thought about doing something different. Since I’m an avid football fan, I thought of ideas to represent players’ usage or involvement over a period (a season, a couple of seasons). I have seen some cool visualisations like donuts which depict usage and I wanted to make something different and simple to understand. I thought about representing batteries as a form of player usage and it made a lot of sense.
GSoC'21: Final Report
Matplotlib: Revisiting Text/Font Handling To kick things off for the final report, here’s a meme to nudge about the previous blogs. About Matplotlib Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations, which has become a de-facto Python plotting library. Much of the implementation behind its font manager is inspired by W3C compliant algorithms, allowing users to interact with font properties like font-size, font-weight, font-family, etc. However, the way Matplotlib handled fonts and general text layout was not ideal, which is what Summer 2021 was all about.
GSoC'21: Quarter Progress
“Matplotlib, I want 多个汉字 in between my text.” Let’s say you asked Matplotlib to render a plot with some label containing 多个汉字 (multiple Chinese characters) in between your English text. Or conversely, let’s say you use a Chinese font with Matplotlib, but you had English text in between (which is quite common). Assumption: the Chinese font doesn’t have those English glyphs, and vice versa With this short writeup, I’ll talk about how does a migration from a font-first to a text-first approach in Matplotlib looks like, which ideally solves the above problem.
The Python Graph Gallery: hundreds of python charts with reproducible code.
Data visualization is a key step in a data science pipeline. Python offers great possibilities when it comes to representing some data graphically, but it can be hard and time-consuming to create the appropriate chart. The Python Graph Gallery is here to help. It displays many examples, always providing the reproducible code. It allows to build the desired chart in minutes. About 400 charts in 40 sections The gallery currently provides more than 400 chart examples.
GSoC'21: Pre-Quarter Progress
“Well? Did you get it working?!” Before I answer that question, if you’re missing the context, check out my previous blog’s last few lines.. promise it won’t take you more than 30 seconds to get the whole problem! With this short writeup, I intend to talk about what we did and why we did, what we did. XD Ostrich Algorithm Ring any bells? Remember OS (Operating Systems)? It’s one of the core CS subjects which I bunked then and regret now.
GSoC'21: Mid-Term Progress
"Aitik, how is your GSoC going?" Well, it’s been a while since I last wrote. But I wasn’t spending time watching Loki either! (that’s a lie.) During this period the project took on some interesting (and stressful) curves, which I intend to talk about in this small writeup. New Mentor! The first week of coding period, and I met one of my new mentors, Jouni. Without him, along with Tom and Antony, the project wouldn’t have moved an inch.
Aitik Gupta joins as a Student Developer under GSoC'21
The day of result, was a very, very long day. With this small writeup, I intend to talk about everything before that day, my experiences, my journey, and the role of Matplotlib throughout! About Me I am a third-year undergraduate student currently pursuing a Dual Degree (B.Tech + M.Tech) in Information Technology at Indian Institute of Information Technology, Gwalior. During my sophomore year, my interests started expanding in the domain of Machine Learning, where I learnt about various amazing open-source libraries like NumPy, SciPy, pandas, and Matplotlib!
Stellar Chart, a Type of Chart to Be on Your Radar
In May 2020, Alexandre Morin-Chassé published a blog post about the stellar chart. This type of chart is an (approximately) direct alternative to the radar chart (also known as web, spider, star, or cobweb chart) — you can read more about this chart here. In this tutorial, we will see how we can create a quick-and-dirty stellar chart. First of all, let’s get the necessary modules/libraries, as well as prepare a dummy dataset (with just a single record).
Figures in the IPCC Special Report on Global Warming of 1.5°C (SR15)
Background Cover of the IPCC SR15 The IPCC’s Special Report on Global Warming of 1.5°C (SR15), published in October 2018, presented the latest research on anthropogenic climate change. It was written in response to the 2015 UNFCCC’s “Paris Agreement” of holding the increase in the global average temperature to well below 2 °C above pre-industrial levels and to pursue efforts to limit the temperature increase to 1.5 °C […]".
GSoD: Developing Matplotlib Entry Paths
Introduction This year’s Google Season of Docs (GSoD) provided me the opportunity to work with the open source organization, Matplotlib. In early summer, I submitted my proposal of Developing Matplotlib Entry Paths with the goal of improving the documentation with an alternative approach to writing. I had set out to identify with users more by providing real world contexts to examples and programming. My purpose was to lower the barrier of entry for others to begin using the Python library with an expository approach.
Visualizing Code-Switching with Step Charts
Introduction Code-switching is the practice of alternating between two or more languages in the context of a single conversation, either consciously or unconsciously. As someone who grew up bilingual and is currently learning other languages, I find code-switching a fascinating facet of communication from not only a purely linguistic perspective, but also a social one. In particular, I’ve personally found that code-switching often helps build a sense of community and familiarity in a group and that the unique ways in which speakers code-switch with each other greatly contribute to shaping group dynamics.
GSoC 2020 Work Product - Baseline Images Problem
Google Summer of Code 2020 is completed. Hurray!! This post discusses about the progress so far in the three months of the coding period from 1 June to 24 August 2020 regarding the project Baseline Images Problem under matplotlib organisation under the umbrella of NumFOCUS organization. Project Details: This project helps with the difficulty in adding/modifying tests which require a baseline image. Baseline images are problematic because Baseline images cause the repo size to grow rather quickly.
GSoC Coding Phase 3 Blog 1
Google Summer of Code 2020’s second evaluation is completed. I passed!!! Hurray! Now we are in the mid way of the last evaluation. This post discusses about the progress so far in the first two weeks of the third coding period from 26 July to 9 August 2020. Completion of the modification logic for the matplotlib_baseline_images package We successfully created the matplotlib_baseline_image_generation command line flag for baseline image generation for matplotlib and mpl_toolkits in the previous months.
GSoC Coding Phase 2 Blog 2
Google Summer of Code 2020’s second evaluation is about to complete. Now we are about to start with the final coding phase. This post discusses about the progress so far in the last two weeks of the second coding period from 13 July to 26 July 2020. Modular approach towards removal of matplotlib baseline images We have divided the work in two parts as discussed in the previous blog. The first part is the generation of the baseline images discussed below.
Elementary Cellular Automata
Cellular automata are discrete models, typically on a grid, which evolve in time. Each grid cell has a finite state, such as 0 or 1, which is updated based on a certain set of rules. A specific cell uses information of the surrounding cells, called it’s neighborhood, to determine what changes should be made. In general cellular automata can be defined in any number of dimensions. A famous two dimensional example is Conway’s Game of Life in which cells “live” and “die”, sometimes producing beautiful patterns.
GSoC Coding Phase 2 Blog 1
Google Summer of Code 2020’s first evaluation is completed. I passed!!! Hurray! Now we are in the mid way of the second evaluation. This post discusses about the progress so far in the first two weeks of the second coding period from 30 June to 12 July 2020. Completion of the matplotlib_baseline_images package We successfully created the matplotlib_baseline_images package. It contains the matplotlib and the matplotlib toolkit baseline images. Symlinking is done for the baseline images, related changes for Travis, appvoyer, azure pipelines etc.
Animate Your Own Fractals in Python with Matplotlib
Imagine zooming an image over and over and never go out of finer details. It may sound bizarre but the mathematical concept of fractals opens the realm towards this intricating infinity. This strange geometry exhibits the same or similar patterns irrespectively of the scale. We can see one fractal example in the image above. The fractals may seem difficult to understand due to their peculiarity, but that’s not the case. As Benoit Mandelbrot, one of the founding fathers of the fractal geometry said in his legendary TED Talk:
GSoC Coding Phase 1 Blog 2
Google Summer of Code 2020’s first evaluation is about to complete. This post discusses about the progress so far in the last two weeks of the first coding period from 15 June to 30 June 2020. Completion of the demo package We successfully created the demo app and uploaded it to the test.pypi. It contains the main and the secondary package. The main package is analogous to the matplotlib and secondary package is analogous to the matplotlib_baseline_images package as discussed in the previous blog.
Animated polar plot with oceanographic data
The ocean is a key component of the Earth climate system. It thus needs a continuous real-time monitoring to help scientists better understand its dynamic and predict its evolution. All around the world, oceanographers have managed to join their efforts and set up a Global Ocean Observing System among which Argo is a key component. Argo is a global network of nearly 4000 autonomous probes or floats measuring pressure, temperature and salinity from the surface to 2000m depth every 10 days.
GSoC Coding Phase 1 Blog 1
I Sidharth Bansal, was waiting for the coding period to start from the March end so that I can make my hands dirty with the code. Finally, coding period has started. Two weeks have passed. This blog contains information about the progress so far from 1 June to 14 June 2020. Movement from mpl-test and mpl packages to mpl and mpl-baseline-images packages Initially, we thought of creating a mpl-test and mpl package.
Pyplot vs Object Oriented Interface
Generating the data points To get acquainted with the basics of plotting with matplotlib, let’s try plotting how much distance an object under free-fall travels with respect to time and also, its velocity at each time step. If, you have ever studied physics, you can tell that is a classic case of Newton’s equations of motion, where $$ v = a \times t $$ $$ S = 0.5 \times a \times t^{2} $$
Emoji Mosaic Art
A while back, I came across this cool repository to create emoji-art from images. I wanted to use it to transform my mundane Facebook profile picture to something more snazzy. The only trouble? It was written in Rust. So instead of going through the process of installing Rust, I decided to take the easy route and spin up some code to do the same in Python using matplotlib. Because that’s what anyone sane would do, right?
Draw all graphs of N nodes
The other day I was homeschooling my kids, and they asked me: “Daddy, can you draw us all possible non-isomorphic graphs of 3 nodes”? Or maybe I asked them that? Either way, we happily drew all possible graphs of 3 nodes, but already for 4 nodes it got hard, and for 5 nodes - plain impossible! So I thought: let me try to write a brute-force program to do it! I spent a few hours sketching some smart dynamic programming solution to generate these graphs, and went nowhere, as apparently the problem is quite hard.
Sidharth Bansal joined as GSoC'20 intern
When I, Sidharth Bansal, heard I got selected in Google Summer of Code(GSOC) 2020 with Matplotlib under Numfocus, I was jumping and dancing. In this post, I talk about my past experiences, how I got selected for GSOC with Matplotlib, and my project details. I am grateful to the community :) About me: I am currently pursuing a Bachelor’s in Technology in Software Engineering at Delhi Technological University, Delhi, India. I started my journey of open source with Public Lab, an open-source organization as a full-stack Ruby on Rails web developer.
Matplotlib Cyberpunk Style
1 - The Basis Let’s make up some numbers, put them in a Pandas dataframe and plot them: import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({'A': [1, 3, 9, 5, 2, 1, 1], 'B': [4, 5, 5, 7, 9, 8, 6]}) df.plot(marker='o') 2 - The Darkness Not bad, but somewhat ordinary. Let’s customize it by using Seaborn’s dark style, as well as changing background and font colors:
Elliott Sales de Andrade hired as Matplotlib Software Research Engineering Fellow
As has been discussed in detail in Nadia Eghbal’s Roads and Bridges, the CZI EOSS program announcement, and in the NumFocus sustainability program goals, much of the critical software that science and industry are built on is maintained by a primarily volunteer community. While this has worked, it is not sustainable in the long term for the health of many projects or their contributors. We are happy to announce that we have hired Elliott Sales de Andrade (QuLogic) as the Matplotlib Software Research Engineering Fellow supported by the Chan Zuckerberg Initiative Essential Open Source Software for Science effective March 1, 2020!
Matplotlib for Making Diagrams
Matplotlib for diagrams This is my first post for the Matplotlib blog so I wanted to lead with an example of what I most love about it: How much control Matplotlib gives you. I like to use it as a programmable drawing tool that happens to be good at plotting data. The default layout for Matplotlib works great for a lot of things, but sometimes you want to exert more control.
Create Ridgeplots in Matplotlib
Introduction This post will outline how we can leverage gridspec to create ridgeplots in Matplotlib. While this is a relatively straightforward tutorial, some experience working with sklearn would be beneficial. Naturally it being a vast undertaking, this will not be an sklearn tutorial, those interested can read through the docs here. However, I will use its KernelDensity module from sklearn.neighbors. Packages import pandas as pd import numpy as np from sklearn.
Create a Tesla Cybertruck That Drives
My name is Ted Petrou, founder of Dunder Data, and in this tutorial you will learn how to create the new Tesla Cybertruck using Matplotlib. I was inspired by the image below which was originally created by Lynn Fisher (without Matplotlib). Before going into detail, let’s jump to the results. Here is the completed recreation of the Tesla Cybertruck that drives off the screen. Tutorial A tutorial now follows containing all the steps that creates a Tesla Cybertruck that drives.
An Inquiry Into Matplotlib's Figures
Preliminaries import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl A Top-Down runnable Jupyter Notebook with the exact contents of this blog can be found here An interactive version of this guide can be accessed on Google Colab A word before we get started… Although a beginner can follow along with this guide, it is primarily meant for people who have at least a basic knowledge of how Matplotlib’s plotting functionality works.
Custom 3D engine in Matplotlib
Matplotlib has a really nice 3D interface with many capabilities (and some limitations) that is quite popular among users. Yet, 3D is still considered to be some kind of black magic for some users (or maybe for the majority of users). I would thus like to explain in this post that 3D rendering is really easy once you’ve understood a few concepts. To demonstrate that, we’ll render the bunny above with 60 lines of Python and one Matplotlib call.
Matplotlib in Data Driven SEO
Search Engine Optimization (SEO) is a process that aims to increase quantity and quality of website traffic by ensuring a website can be found in search engines for phrases that are relevant to what the site is offering. Google is the most popular search engine in the world and presence in top search results is invaluable for any online business since click rates drop exponentially with ranking position. Since the beginning, specialized entities have been decoding signals that influence position in search engine result page (SERP) focusing on e.
Creating the Warming Stripes in Matplotlib
Earth’s temperatures are rising and nothing shows this in a simpler, more approachable graphic than the “Warming Stripes”. Introduced by Prof. Ed Hawkins they show the temperatures either for the global average or for your region as colored bars from blue to red for the last 170 years, available at #ShowYourStripes. The stripes have since become the logo of the Scientists for Future. Here is how you can recreate this yourself using Matplotlib.
Using Matplotlib to Advocate for Postdocs
Postdocs are the workers of academia. They are the main players beyond the majority of scientific papers published in journals and conferences. Yet, their effort is often not recognized in terms of salary and benefits. A few years ago, the NIH has established stipend levels for undergraduate, predoctoral and postdoctoral trainees and fellows, the so-called NIH guidelines. Many universities and research institutes currently adopt these guidelines for deciding how much to pay postdocs.