tanszek:oktatas:muszaki_informatika:matplotlib_cheatsheet
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| tanszek:oktatas:muszaki_informatika:matplotlib_cheatsheet [2026/02/27 08:49] – created szabom | tanszek:oktatas:muszaki_informatika:matplotlib_cheatsheet [2026/02/27 08:56] (current) – szabom | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ^ Ábra és tengely létrehozás | + | ^ Ábra és tengely létrehozás |
| - | | plt.figure() | + | | plt.figure() |
| - | | plt.subplots() | + | | plt.subplots() |
| - | ^ Alap grafikon típusok | + | ^ Alap grafikon típusok |
| - | | plot(x, y) | + | | plot(x, y) | Vonaldiagram. |
| - | | scatter(x, y) | Pontdiagram. | + | | scatter(x, y) |
| - | | bar(x, height) | + | | bar(x, height) |
| - | | hist(data, bins=...) | + | | hist(data, bins=...) |
| - | | boxplot(data) | + | | boxplot(data) |
| - | | imshow(matrix) | + | | imshow(matrix) |
| - | | | + | ^ Címek és tengelyfeliratok |
| - | | | | + | | set_title(" |
| - | | | | + | | set_xlabel() / set_ylabel() |
| - | | | + | ^ Tengelyek kezelése |
| - | | | | + | | set_xlim() / set_ylim() |
| - | | | | + | | set_xticks() / set_yticks() |
| - | | | | + | | tick_params() |
| - | | | + | ^ Jelmagyarázat |
| - | | | | + | | legend() |
| - | | | + | ^ Rács és stílus |
| - | | | | + | | grid(True) |
| - | | | | + | | plt.style.use(" |
| - | | | + | ^ Layout |
| - | | | | + | | tight_layout() |
| - | | | | + | | subplots_adjust() |
| - | | | | + | ^ Extra vizualizációs elemek |
| - | | | | + | | colorbar() |
| + | | annotate() | ||
| + | |||
| + | |||
| + | **Feladat** | ||
| + | |||
| + | - Generálj 500 normál eloszlású adatot. | ||
| + | - Készíts 2×2 subplot elrendezést. | ||
| + | - Tartalmazza: | ||
| + | - Vonaldiagram (kumulatív összeg) | ||
| + | - Hisztogram | ||
| + | - Scatter plot | ||
| + | - Boxplot | ||
| + | - Használj: | ||
| + | - címet | ||
| + | - tengelyfeliratokat | ||
| + | - grid-et | ||
| + | - legend-et | ||
| + | - tengelykorlátot | ||
| + | - annotate-et | ||
| + | - style-t | ||
| + | - tight_layout-ot | ||
| + | |||
| + | <sxh python> | ||
| + | |||
| + | import numpy as np import matplotlib.pyplot as plt | ||
| + | |||
| + | #Stílus | ||
| + | plt.style.use(" | ||
| + | |||
| + | #Adat generálás | ||
| + | np.random.seed(42) | ||
| + | data = np.random.randn(500) | ||
| + | x = np.arange(len(data)) | ||
| + | |||
| + | #Ábra és subplotok | ||
| + | fig, axs = plt.subplots(2, | ||
| + | |||
| + | #1. VONALDIAGRAM | ||
| + | cumsum = np.cumsum(data) | ||
| + | |||
| + | axs[0, | ||
| + | axs[0, | ||
| + | axs[0, | ||
| + | axs[0, | ||
| + | axs[0, | ||
| + | axs[0, | ||
| + | |||
| + | # | ||
| + | axs[0, | ||
| + | |||
| + | # | ||
| + | max_idx = np.argmax(cumsum) | ||
| + | axs[0, | ||
| + | xy=(max_idx, | ||
| + | xytext=(max_idx, | ||
| + | arrowprops=dict()) | ||
| + | |||
| + | #2. HISZTOGRAM | ||
| + | |||
| + | axs[0, | ||
| + | axs[0, | ||
| + | axs[0, | ||
| + | axs[0, | ||
| + | axs[0, | ||
| + | |||
| + | #3. SCATTER | ||
| + | |||
| + | y = np.random.randn(500) | ||
| + | |||
| + | sc = axs[1, | ||
| + | axs[1, | ||
| + | axs[1, | ||
| + | axs[1, | ||
| + | axs[1, | ||
| + | |||
| + | #4. BOXPLOT | ||
| + | |||
| + | axs[1, | ||
| + | axs[1, | ||
| + | axs[1, | ||
| + | |||
| + | #Layout optimalizálás | ||
| + | plt.tight_layout() | ||
| + | |||
| + | plt.show() | ||
| + | </ | ||
tanszek/oktatas/muszaki_informatika/matplotlib_cheatsheet.1772182158.txt.gz · Last modified: 2026/02/27 08:49 by szabom
