tanszek:oktatas:muszaki_informatika:matplotlib_cheatsheet
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tanszek:oktatas:muszaki_informatika:matplotlib_cheatsheet [2026/02/27 08:53] – [Table] 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) | Vonaldiagram. | | plot(x, y) | Vonaldiagram. | ||
| | scatter(x, y) | Pontdiagram. | | scatter(x, y) | Pontdiagram. | ||
| Line 9: | Line 9: | ||
| | boxplot(data) | | boxplot(data) | ||
| | imshow(matrix) | | imshow(matrix) | ||
| - | ^ Címek és tengelyfeliratok | + | ^ Címek és tengelyfeliratok |
| | set_title(" | | set_title(" | ||
| | set_xlabel() / set_ylabel() | | set_xlabel() / set_ylabel() | ||
| - | ^ Tengelyek kezelése | + | ^ Tengelyek kezelése |
| | set_xlim() / set_ylim() | | set_xlim() / set_ylim() | ||
| | set_xticks() / set_yticks() | | set_xticks() / set_yticks() | ||
| | tick_params() | | tick_params() | ||
| - | ^ Jelmagyarázat | + | ^ Jelmagyarázat |
| | legend() | | legend() | ||
| - | ^ Rács és stílus | + | ^ Rács és stílus |
| | grid(True) | | grid(True) | ||
| | plt.style.use(" | | plt.style.use(" | ||
| - | ^ Layout | + | ^ Layout |
| | tight_layout() | | tight_layout() | ||
| | subplots_adjust() | | subplots_adjust() | ||
| - | ^ Extra vizualizációs elemek | + | ^ Extra vizualizációs elemek |
| | colorbar() | | colorbar() | ||
| | annotate() | | 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.1772182402.txt.gz · Last modified: 2026/02/27 08:53 by szabom
