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 27: | Line 27: | ||
| | 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.1772182429.txt.gz · Last modified: 2026/02/27 08:53 by szabom
