A Pokémon Types Table In Python

Hi there. This page is on generating a Pokémon types table in the Python programming language. You can create something similar to the table below.

 

Source: https://img.pokemondb.net/images/typechart.png

 

 


Setup

The code to generate the table plot with Python is not that long. Start with importing seaborn as sns, numpy as np and matplotlib’s pyplot as plt.

A list of Pokémon types (Generation 6+) is created into Python. This list will be for the plot labels.

The part that takes a while to set up is the two-dimensional Numpy array. Numeric values are either 0, 1/2, 1 or 2. This Numpy list is a replication of the Pokémon table chart above.

Refer to the list below for the number meanings.

 

  • 0: Attack type does no damage to the defending Pokémon
  • 0.5: Attack Of that type does half the normal damage to the defending Pokémon
  • 1: Attack Of that type does normal damage to the defending Pokémon
  • 2: Attack Of that type does double the normal damage to the defending Pokémon

 

Note that the list above refers to single type defending Pokémon and not dual typed ones. For dual typed defending Pokémon use the chart twice. As an example, a fire type move on a Water/Dragon Pokémon would do one quarter of the normal damage because of half damage from fire to water and another half damage from fire to dragon. (0.5 x 0.5 = 0.25)

 

 

 

 


Creating The Pokémon Types Table

Most of the hard work has been done. Generating the plot does not require too much code. From my own (Google) research, it is easier and better to use Seaborn for plotting heatmaps with labels than with matplotlib.

The main function that is used is Seaborn’s heatmap() function. It it key to use the annot = argument along with the xticklabels and the yticklabels. The argument cmap = “Greens” is for having the colours in the green shade.

Labels and a title with changed sizes are added to the plot.

 

 

Leave a Reply