Meta tags:
description= Erstelle ein- und mehrpanelige Abbildungen mit Matplotlib Subplots: plt.subplots(), GridSpec, gemeinsame Achsen, Größen und Speicherbeispiele.;
Headings (most frequently used words):
achsen, subplots, und, eine, matplotlib, vollständige, anleitung, der, schnellste, weg, plt, erstellen, eines, rasters, über, iterieren, gemeinsam, nutzen, direkt, entpacken, individuelle, layouts, mit, gridspec, zeilen, spaltenhöhen, steuern, gemeinsame, abbildungsgröße, festlegen, titel, beschriftungen, hinzufügen, mehrteilige, abbildung, speichern, häufige, fallstricke, kurzübersicht, verwandte, kapitel, tight_layout, vergessen, falsche, indexdimensionen, suptitle, wird, abgeschnitten,
Text of the page (most frequently used words):
plt (60), python (56), #matplotlib (43), axes (41), color (35), subplots (27), plot (27), und (24), fig (24), set_title (23), sin (22), import (20), gridspec (16), cos (16), lernen (15), der (14), ax1 (14), kopieren (14), tight_layout (14), ax2 (13), show (13), numpy (13), mysql (13), ein (12), die (12), figsize (12), mongodb (12), auf (11), achsen (10), add_subplot (10), array (10), oder (10), steelblue (10), pyplot (10), für (9), abbildung (9), row (9), darkorange (9), linspace (9), alle (8), titel (8), erstellen (8), suptitle (8), true (8), ax3 (8), ist (8), listen (8), html (7), mit (7), spalten (7), top (7), strings (7), elemente (7), über (6), eine (6), hinzufügen (6), zeilen (6), grid (6), layout (6), raster (6), panels (6), seagreen (6), wenn (6), bottom (6), ncols (6), nrows (6), von (6), tan (6), string (6), w3docs (5), tools (5), das (5), beschriftungen (5), entpacken (5), variablen (5), daten (5), savefig (5), for (5), durchlaufen (5), einem (5), einen (5), power (5), set_ylabel (5), als (5), erste (5), tutorial (5), tuples (5), methoden (5), formatter (5), json (4), code (4), generator (4), kapitel (4), layouts (4), direkt (4), achsenbeschriftungen (4), false (4), immer (4), sharex (4), col (4), zelle (4), zugreifen (4), verwende (4), gibt (4), zurück (4), sich (4), 300 (4), functions (4), set_xlabel (4), zeile (4), den (4), right (4), ax4 (4), left (4), figure (4), dateien (4), entfernen (4), schritte (4), regression (4), dictionaries (4), set (4), listenelemente (4), encoder (3), editor (3), quizze (3), übungen (3), php (3), javascript (3), css (3), speichern (3), gemeinsame (3), abbildungsgröße (3), steuern (3), iterieren (3), weg (3), scatter (3), bbox_inches (3), tight (3), height_ratios (3), squeeze (3), sharey (3), flat (3), kann (3), dies (3), wird (3), subplot (3), rufe (3), vor (3), fontsize (3), linestyle (3), zip (3), jedes (3), nicht (3), tomato (3), wide (3), ax_br (3), ax_bm (3), ax_bl (3), three (3), ax_top (3), linewidth (3), panel (3), legend (3), label (3), the (3), colors (3), mehrere (3), sets (3), italiano (2), português (2), español (2), français (2), русский (2), deutsch (2), english (2), beautifier (2), diff (2), password (2), java (2), git (2), bücher (2), snippets (2), verwandte (2), kurzübersicht (2), häufige (2), fallstricke (2), mehrteilige (2), festlegen (2), spaltenhöhen (2), individuelle (2), gemeinsam (2), nutzen (2), eines (2), rasters (2), schnellste (2), this (2), page (2), zwischen (2), plots (2), vergleichen (2), labels (2), darstellen (2), diagramm (2), getting (2), started (2), introduction (2), png (2), dpi (2), 150 (2), title (2), abbildungstitel (2), achse (2), teilen (2), rect (2), abgeschnitten (2), aus (2), übergib (2), erhalten (2), überlappen (2), oft (2), zuerst (2), objekt (2), gesamte (2), übergeordneten (2), kannst (2), werte (2), sind (2), abstand (2), wspace (2), hspace (2), short (2), narrow (2), tall (2), 400 (2), column (2), wider (2), than (2), width_ratios (2), andere (2), syntax (2), nur (2), columns (2), bei (2), jede (2), zwei (2), klein (2), skala (2), links (2), dieselbe (2), sodass (2), black (2), name (2), clip (2), names (2), arctan (2), exp (2), y_tan (2), 200 (2), standard (2), pip (2), einer (2), vollständige (2), anleitung (2), and (2), handling (2), zahlen (2), klassen (2), limit (2), update (2), drop (2), collection (2), delete (2), insert (2), datenbank (2), einführung (2), schleifen (2), verbinden (2), ändern (2), hash (2), 2026, rechte, vorbehalten, entwickler, gemacht, sprache, datenschutzrichtlinie, kontakt, uns, unternehmen, probier, üben, kostenlose, tutorials, beispiele, web, seit, 2014, next, previous, yes, was, helpful, datenverteilungen, histograms, beziehungen, kategorien, bar, charts, rasterlinien, gestalten, anmerkungen, kontinuierliche, line, dein, erstes, bibliotheksübersicht, installation, out, höhenverhältnisse, überspannen, rows, cols, individuelles, zellen, aufgabe, stattdessen, subplots_adjust, leave, durch, werden, behebe, indem, übergibst, now, shape, always, index, with, versuch, verwenden, löst, entweder, indexerror, falsche, indexdimensionen, ohne, benachbarter, vergessen, schneidet, überschüssigen, leerraum, herum, nützlich, beim, einbetten, des, bildes, dokument, webseite, trig_panels, aufgerufen, gelöscht, alpha, latex, 100, hat, seinen, eigenen, eigene, haben, nach, deinen, anpassen, ausgangspunkte, platz, lassen, empfohlene, parameter, bezieht, einzelne, gute, faustregel, vertikalen, horizontalen, bruchteil, durchschnittlichen, höhe, breite, proportional, side, main, taller, akzeptiert, einige, größer, machen, slice, spiegelt, slicing, erstreckt, drei, nimmt, equal, overview, one, spanning, all, erstellt, denen, gleich, groß, ungleiche, breites, übersichtspanel, oben, detailpanels, darunter, sauberer, kurze, verschachtle, linear, natural, log, log1p, square, root, unpack, into, named, voraus, bekannt, zurückgegebene, benannte, entfernt, doppelten, oberen, hält, ausgerichtet, entsprechend, spaltenübergreifend, übereinstimmen, muss, labelbottom, tick_params, hide, redundant, tick, radians, shared, axis, example, horizontal, vertical, größe, gleicher, bereich, gleiche, verknüpfe, ihre, schwenken, zoomen, anderen, aktualisiert, eindimensionalen, iterator, unabhängig, rasterform, schleife, funktioniert, axvline, axhline, keep, from, dominating, scale, großen, einfacher, geglättete, manuell, indizieren, fügt, allen, hinzu, versatz, schiebt, ihn, paneltiteln, obersten, trigonometric, exponential, clipped, clamp, avoid, spikes, sowohl, auch, zweidimensionales, indiziere, wobei, beide, indizes, nullbasiert, einzelnes, kein, passt, automatisch, legt, zoll, fest, standardwert, width, height, wichtige, punkte, cosine, sine, standardmäßige, einstiegspunkt, objekten, neu, bibliothek, bist, lies, install, bevor, beginnst, installiere, falls, noch, geschehen, ermöglichen, dir, diagramme, einzigen, platzieren, anstatt, separate, fenster, ordnest, sie, nebeneinander, übereinander, individuellen, damit, leser, blick, dieses, behandelt, alles, einfachen, zweipaneligen, bis, hin, flexiblen, rasterlayouts, gemeinsamen, zellenübergreifenden, spans, erstelle, mehrpanelige, abbildungen, größen, speicherbeispiele, http, anfragen, pytest, pakete, virtuelle, umgebungen, tooling, best, practices, threading, asyncio, concurrency, csv, random, sys, itertools, collections, ausnahmen, auslösen, error, library, addieren, umkehren, duplikate, how, enums, abstrakte, kapselung, polymorphismus, dataclasses, static, classmethod, property, magic, methods, advanced, oop, match, anweisung, enumerate, map, comprehensions, kontextmanager, rekursion, closures, generatoren, decorators, args, kwargs, type, hints, intermediate, sort, query, find, join, table, order, where, select, tabelle, einstieg, nearest, neighbors, auc, roc, kurve, cross, validation, bootstrap, aggregation, means, kategoriale, search, logistische, hierarchisches, clustering, konfusionsmatrix, entscheidungsbaum, train, test, skalierung, multiple, polynomiale, lineare, streudiagramm, normalverteilung, datenverteilung, perzentil, standardabweichung, mittelwert, median, modus, machine, learning, kreisdiagramme, histogramme, balken, linie, marker, plotting, django, scipy, pandas, modules, löschen, schreiben, lesen, dateiverarbeitung, file, formatierung, benutzereingabe, try, except, regex, math, datumsangaben, module, scope, iteratoren, vererbung, objekte, arrays, lambda, funktionen, while, else, tupeln, gruppieren, operatoren, booleans, casting, datentypen, kommentare, variablennamen, aktualisieren, tupel, tuple, sortieren, slicen, home, ausgabevariablen, verschachtelte, modifizieren, list, comprehension, zusammenführen, globale, format, escape, zeichen, dictionary, verketten, zuweisen, aufrufen, anmelden, durchsuchen, formatters, url, reverse, sha256, md5, length, calculator, hsl, hex, mixer, converter, picker, general, kurse,
Text of the page (random words):
en php lernen python lernen kurse quizze übungen snippets tools general tools html editor password generator html encoder code diff json beautifier alle 13 color tools color picker color converter color mixer color hex colors hsl alle 10 string tools string length calculator md5 hash generator sha256 hash generator string reverse url encoder alle 19 code formatters javascript formatter css formatter html formatter json formatter php formatter w3docs durchsuchen k de english en deutsch de русский ru français fr español es português pt italiano it anmelden python lernen python tutorial auf elemente zugreifen auf listenelemente zugreifen auf set elemente zugreifen tuples aufrufen elemente hinzufügen listenelemente hinzufügen set elemente hinzufügen mehrere werte zuweisen elemente ändern listenelemente ändern strings verketten dictionaries kopieren listen kopieren dictionary methoden escape zeichen format strings globale variablen listen verbinden sets zusammenführen tuples verbinden list comprehension listen methoden dictionaries durchlaufen listen durchlaufen sets durchlaufen tuples durchlaufen strings modifizieren verschachtelte dictionaries ausgabevariablen python home python listen python sets python strings python tuples python variablen elemente entfernen listenelemente entfernen set elemente entfernen set methoden strings slicen listen sortieren string methoden tuple methoden tupel entpacken tuples aktualisieren variablennamen python einführung python erste schritte python syntax python kommentare python variablen python datentypen python zahlen python casting python strings python booleans python operatoren python listen python tupeln gruppieren python dictionaries python if else python while schleifen python for schleifen python funktionen python lambda python arrays python klassen objekte python vererbung python iteratoren python scope python module python datumsangaben python math python json python regex python pip python try except python benutzereingabe python string formatierung file handling python dateiverarbeitung python dateien lesen python dateien schreiben erstellen python dateien löschen python modules numpy tutorial pandas tutorial scipy tutorial django tutorial python matplotlib matplotlib einführung matplotlib erste schritte matplotlib pyplot matplotlib plotting matplotlib marker matplotlib linie matplotlib beschriftungen matplotlib grid matplotlib subplot matplotlib scatter matplotlib balken matplotlib histogramme matplotlib kreisdiagramme machine learning erste schritte mittelwert median modus standardabweichung perzentil datenverteilung normalverteilung von daten streudiagramm lineare regression polynomiale regression multiple regression skalierung train test entscheidungsbaum konfusionsmatrix hierarchisches clustering logistische regression grid search kategoriale daten k means bootstrap aggregation cross validation auc roc kurve k nearest neighbors python mysql mysql einstieg mysql datenbank erstellen mysql tabelle erstellen mysql insert mysql select mysql where mysql order by mysql delete mysql drop table mysql update mysql limit mysql join python mongodb mongodb erste schritte mongodb datenbank erstellen mongodb collection erstellen mongodb insert mongodb find mongodb query mongodb sort mongodb delete mongodb drop collection mongodb update mongodb limit intermediate python f strings type hints args kwargs decorators generatoren closures rekursion kontextmanager comprehensions enumerate zip map match anweisung advanced oop magic methods property static classmethod dataclasses polymorphismus kapselung abstrakte klassen enums python how to listen duplikate entfernen string umkehren zwei zahlen addieren error handling and the standard library ausnahmen auslösen collections itertools os sys random csv dateien concurrency in python asyncio threading python tooling and best practices virtuelle umgebungen pakete pytest http anfragen matplotlib subplots vollständige anleitung erstelle ein und mehrpanelige abbildungen mit matplotlib subplots plt subplots gridspec gemeinsame achsen größen und speicherbeispiele subplots ermöglichen es dir mehrere diagramme in einer einzigen matplotlib abbildung zu platzieren anstatt für jedes diagramm separate fenster zu erstellen ordnest du sie in einem raster an nebeneinander übereinander oder in einem individuellen layout damit der leser daten auf einen blick vergleichen kann dieses kapitel behandelt alles von einer einfachen zweipaneligen abbildung bis hin zu flexiblen rasterlayouts mit gemeinsamen achsen und zellenübergreifenden spans bevor du beginnst installiere matplotlib falls noch nicht geschehen pip install matplotlib numpy kopieren wenn du neu in der bibliothek bist lies zuerst die kapitel matplotlib introduction und getting started der schnellste weg plt subplots plt subplots nrows ncols ist der standardmäßige einstiegspunkt er gibt ein figure und ein array von axes objekten zurück import matplotlib pyplot as plt import numpy as np fig axes plt subplots nrows 1 ncols 2 figsize 10 4 x np linspace 0 2 np pi 200 axes 0 plot x np sin x color steelblue axes 0 set_title sine axes 0 set_xlabel x axes 0 set_ylabel sin x axes 1 plot x np cos x color darkorange axes 1 set_title cosine axes 1 set_xlabel x axes 1 set_ylabel cos x plt tight_layout plt show kopieren wichtige punkte figsize width height legt die abbildungsgröße in zoll fest der standardwert ist 6 4 4 8 der für mehrere panels oft zu klein ist plt tight_layout passt den abstand automatisch an sodass sich titel und beschriftungen nicht überlappen rufe es direkt vor show oder savefig auf wenn ncols 1 und nrows 1 der standard ist axes ein einzelnes axes objekt und kein array erstellen eines 2 2 rasters übergib sowohl nrows als auch ncols um ein zweidimensionales numpy array von axes zu erhalten indiziere es mit row col wobei beide indizes nullbasiert sind import matplotlib pyplot as plt import numpy as np x np linspace 0 2 np pi 200 fig ax plt subplots nrows 2 ncols 2 figsize 10 8 top left ax 0 0 plot x np sin x color steelblue ax 0 0 set_title sin x top right ax 0 1 plot x np cos x color darkorange ax 0 1 set_title cos x bottom left clamp tan to avoid spikes y_tan np clip np tan x 10 10 ax 1 0 plot x y_tan color seagreen ax 1 0 set_title tan x clipped bottom right ax 1 1 plot x np exp x np pi color tomato ax 1 1 set_title exp x π plt suptitle trigonometric exponential functions fontsize 14 y 1 02 plt tight_layout plt show kopieren plt suptitle fügt einen übergeordneten abbildungstitel über allen subplots hinzu der versatz y 1 02 schiebt ihn von den paneltiteln der obersten zeile weg über achsen iterieren bei einem großen raster ist es einfacher über das geglättete achsen array zu iterieren als jede zelle manuell zu indizieren import matplotlib pyplot as plt import numpy as np functions np sin np cos np tan np arctan names sin cos tan arctan colors steelblue darkorange seagreen tomato x np linspace np pi np pi 300 fig axes plt subplots 2 2 figsize 10 8 for ax fn name color in zip axes flat functions names colors y fn x y np clip y 5 5 keep tan from dominating the scale ax plot x y color color ax set_title name ax axhline 0 color black linewidth 0 6 linestyle ax axvline 0 color black linewidth 0 6 linestyle plt tight_layout plt show kopieren axes flat gibt einen eindimensionalen iterator zurück unabhängig von der rasterform dieselbe schleife funktioniert für 2 2 3 3 oder jedes andere layout achsen gemeinsam nutzen wenn panels dieselbe größe darstellen gleicher x bereich oder gleiche y skala verknüpfe ihre achsen sodass schwenken oder zoomen in einem panel alle anderen aktualisiert import matplotlib pyplot as plt import numpy as np x np linspace 0 4 np pi 400 sharex true links horizontal axes sharey true links vertical axes fig ax1 ax2 plt subplots 2 1 figsize 8 6 sharex true ax1 plot x np sin x color steelblue ax1 set_ylabel sin x ax1 set_title shared x axis example ax2 plot x np sin 2 x color darkorange ax2 set_ylabel sin 2x ax2 set_xlabel x radians hide redundant x tick labels on the top panel ax1 tick_params labelbottom false plt tight_layout plt show kopieren sharex true entfernt die doppelten x achsenbeschriftungen aus den oberen panels und hält alle panels ausgerichtet verwende sharey true entsprechend wenn die y skala spaltenübergreifend übereinstimmen muss achsen direkt entpacken wenn das layout klein und im voraus bekannt ist kannst du das zurückgegebene array direkt in benannte variablen entpacken import matplotlib pyplot as plt import numpy as np 1 row 3 columns unpack into three named axes fig ax1 ax2 ax3 plt subplots 1 3 figsize 13 4 x np linspace 0 10 300 ax1 plot x x 0 5 color steelblue label x ax1 set_title square root ax1 legend ax2 plot x np log1p x color darkorange label ln 1 x ax2 set_title natural log ax2 legend ax3 plot x x color seagreen label x ax3 set_title linear ax3 legend plt tight_layout plt show kopieren dies ist sauberer als axes 0 axes 1 axes 2 für kurze layouts für ein 2 d raster mit zwei zeilen verschachtle das entpacken ax1 ax2 ax3 ax4 axes individuelle layouts mit gridspec plt subplots erstellt nur raster bei denen jede zelle gleich groß ist für ungleiche layouts ein breites übersichtspanel oben mit detailpanels darunter verwende matplotlib gridspec gridspec import matplotlib pyplot as plt import matplotlib gridspec as gridspec import numpy as np x np linspace 0 2 np pi 300 fig plt figure figsize 10 8 gs gridspec gridspec nrows 2 ncols 3 figure fig top row one wide panel spanning all three columns ax_top fig add_subplot gs 0 ax_top plot x np sin x color steelblue linewidth 2 ax_top set_title overview sin x bottom row three equal panels ax_bl fig add_subplot gs 1 0 ax_bl plot x np sin x color steelblue ax_bl set_title sin x ax_bm fig add_subplot gs 1 1 ax_bm plot x np cos x color darkorange ax_bm set_title cos x ax_br fig add_subplot gs 1 2 ax_br plot x np sin x np cos x color seagreen ax_br set_title sin x cos x plt tight_layout plt show kopieren die gs row col slice syntax spiegelt numpy slicing wider gs 0 erstreckt sich über alle drei spalten gs 1 0 nimmt nur die erste zelle in zeile 1 zeilen und spaltenhöhen steuern gridspec akzeptiert height_ratios und width_ratios um einige zeilen oder spalten größer als andere zu machen import matplotlib pyplot as plt import matplotlib gridspec as gridspec import numpy as np fig plt figure figsize 9 7 gs gridspec gridspec 2 2 height_ratios 3 1 top row is 3 taller than bottom row width_ratios 2 1 left column is 2 wider than right column hspace 0 4 wspace 0 3 x np linspace 0 4 np pi 400 ax1 fig add_subplot gs 0 0 ax1 plot x np sin x color steelblue ax1 set_title main tall wide ax2 fig add_subplot gs 0 1 ax2 plot x np cos x color darkorange ax2 set_title side tall narrow ax3 fig add_subplot gs 1 0 ax3 plot x np sin x 2 color seagreen ax3 set_title bottom left short wide ax4 fig add_subplot gs 1 1 ax4 plot x np cos x 2 color tomato ax4 set_title bottom right short narrow plt suptitle proportional grid layout fontsize 13 plt show kopieren hspace und wspace steuern den vertikalen und horizontalen abstand zwischen subplots als bruchteil der durchschnittlichen subplot höhe breite eine gemeinsame abbildungsgröße festlegen der parameter figsize bezieht sich immer auf die gesamte abbildung nicht auf einzelne subplots eine gute faustregel layout empfohlene figsize 1 zeile 2 spalten 10 4 1 zeile 3 spalten 13 4 2 zeilen 2 spalten 10 8 3 zeilen 3 spalten 13 11 du kannst die werte je nach deinen daten anpassen dies sind ausgangspunkte die platz für titel und beschriftungen lassen titel und beschriftungen hinzufügen jedes axes objekt hat seinen eigenen titel und eigene achsenbeschriftungen die gesamte abbildung kann einen übergeordneten titel haben import matplotlib pyplot as plt import numpy as np fig axes plt subplots 1 2 figsize 10 4 x np linspace 0 5 100 for ax power color in zip axes 2 3 steelblue darkorange ax plot x x power color color ax set_title f x power latex in title ax set_xlabel x ax set_ylabel f x power ax grid true linestyle alpha 0 5 plt suptitle power functions fontsize 14 plt tight_layout plt show kopieren eine mehrteilige abbildung speichern rufe plt savefig vor plt show auf wenn show zuerst aufgerufen wird wird die abbildung gelöscht import matplotlib pyplot as plt import numpy as np fig axes plt subplots 1 3 figsize 13 4 x np linspace 0 2 np pi 300 axes 0 plot x np sin x color steelblue axes 0 set_title sin x axes 1 plot x np cos x color darkorange axes 1 set_title cos x axes 2 plot x np sin x np cos x color seagreen axes 2 set_title sin x cos x plt tight_layout plt savefig trig_panels png dpi 150 bbox_inches tight plt show kopieren bbox_inches tight schneidet überschüssigen leerraum um die abbildung herum ab nützlich beim einbetten des bildes in ein dokument oder eine webseite häufige fallstricke tight_layout vergessen ohne tight_layout überlappen sich subplot titel und achsenbeschriftungen benachbarter panels oft rufe es immer vor show oder savefig auf falsche indexdimensionen plt subplots 2 3 gibt ein 2 d array zurück plt subplots 1 3 gibt ein 1 d array zurück der versuch axes 0 0 auf einem 1 d array zu verwenden löst einen indexerror aus verwende entweder axes 0 oder übergib squeeze false um immer ein 2 d array zu erhalten fig axes plt subplots 1 3 squeeze false axes is now shape 1 3 always index with row col axes 0 0 plot axes 0 1 plot axes 0 2 plot kopieren suptitle wird abgeschnitten plt suptitle kann durch tight_layout abgeschnitten werden behebe dies indem du ein rect an tight_layout übergibst plt tight_layout rect 0 0 1 0 95 leave 5 at top for suptitle kopieren oder verwende stattdessen fig subplots_adjust top 0 90 kurzübersicht aufgabe code 1 2 raster fig ax1 ax2 plt subplots 1 2 2 2 raster fig ax plt subplots 2 2 auf zelle zugreifen ax row col alle zellen durchlaufen for ax in axes flat x achse teilen plt subplots 2 1 sharex true y achse teilen plt subplots 1 2 sharey true immer 2 d array plt subplots squeeze false individuelles layout gs gridspec rows cols fig add_subplot gs r c spalten überspannen fig add_subplot gs 0 höhenverhältnisse gridspec 2 1 height_ratios 3 1 abbildungstitel plt suptitle title abbildung speichern plt savefig out png dpi 150 bbox_inches tight verwandte kapitel matplotlib introduction bibliotheksübersicht und installation matplotlib getting started dein erstes diagramm matplotlib line plots kontinuierliche daten darstellen matplotlib labels achsenbeschriftungen titel und anmerkungen matplotlib grid rasterlinien hinzufügen und gestalten matplotlib bar charts kategorien vergleichen matplotlib scatter plots beziehungen zwischen variablen matplotlib histograms datenverteilungen was this page helpful yes no previous matplotlib grid next matplotlib scatter on this page der schnellste weg plt subplots erstellen eines 2 2 rasters über achsen iterieren achsen gemeinsam nutzen achsen direkt entpacken individuelle layouts mit gridspec zeilen und spaltenhöhen steuern eine gemeinsame abbildungsgröße...
|