Skip to content

Instantly share code, notes, and snippets.

@DATAUNIRIO
Last active September 12, 2025 17:48
Show Gist options
  • Select an option

  • Save DATAUNIRIO/2a1131c5d6b3979eba840a9881ffd736 to your computer and use it in GitHub Desktop.

Select an option

Save DATAUNIRIO/2a1131c5d6b3979eba840a9881ffd736 to your computer and use it in GitHub Desktop.
Dotplot no Python
# Importando as bibliotecas do python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
familias = pd.read_excel("https://github.com/DATAUNIRIO/dados_para_aula/raw/refs/heads/main/excel/Familias.xls")
familias.head()
def dotplot(input_x, **args):
# Count how many times does each value occur
unique_values, counts = np.unique(input_x, return_counts=True)
# Convert 1D input into 2D array
scatter_x = [] # x values
scatter_y = [] # corresponding y values
for idx, value in enumerate(unique_values):
for counter in range(1, counts[idx]+1):
scatter_x.append(value)
scatter_y.append(counter)
# draw dot plot using scatter()
plt.scatter(scatter_x, scatter_y, **args)
# Optional - show all unique values on x-axis.
# Matplotlib might hide some of them
plt.gca().set_xticks(unique_values)
dotplot(input_x=familias.tam)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment