Last active
September 12, 2025 17:48
-
-
Save DATAUNIRIO/2a1131c5d6b3979eba840a9881ffd736 to your computer and use it in GitHub Desktop.
Dotplot no Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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