Personnaliser les préférences

Nous utilisons des cookies pour vous aider à naviguer efficacement et à exécuter certaines fonctions. Vous trouverez ci-dessous des informations détaillées sur tous les cookies sous chaque catégorie de consentement.

Les cookies classés comme « Nécessaires » sont stockés sur votre navigateur car ils sont essentiels pour activer les fonctionnalités de base du site.... 

Toujours actif

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Aucun cookie à afficher.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

Aucun cookie à afficher.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Aucun cookie à afficher.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Aucun cookie à afficher.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

Aucun cookie à afficher.

Comment ajuster la taille de la sous-parcelle dans Matplotlib



Vous pouvez utiliser la syntaxe suivante pour ajuster la taille des sous-parcelles dans Matplotlib :

#specify one size for all subplots
fig, ax = plt.subplots(2, 2, figsize=(10,7))

#specify individual sizes for subplots
fig, ax = plt.subplots(1, 2, gridspec_kw={'width_ratios': [3, 1]})

Les exemples suivants montrent comment utiliser cette syntaxe dans la pratique.

Exemple 1 : Spécifier une taille pour toutes les sous-parcelles

Le code suivant montre comment spécifier une taille pour tous les sous-tracés :

import matplotlib.pyplot as plt

#define subplots
fig, ax = plt.subplots(2, 2, figsize=(10,7))
fig.tight_layout()

#define data
x = [1, 2, 3]
y = [7, 13, 24]

#create subplots
ax[0, 0].plot(x, y, color='red')
ax[0, 1].plot(x, y, color='blue')
ax[1, 0].plot(x, y, color='green')
ax[1, 1].plot(x, y, color='purple')

Nous pouvons facilement modifier la taille des sous-traces en modifiant les valeurs de l’argument figsize :

import matplotlib.pyplot as plt

#define subplots
fig, ax = plt.subplots(2, 2, figsize=(5,5))
fig.tight_layout()

#define data
x = [1, 2, 3]
y = [7, 13, 24]

#create subplots
ax[0, 0].plot(x, y, color='red')
ax[0, 1].plot(x, y, color='blue')
ax[1, 0].plot(x, y, color='green')
ax[1, 1].plot(x, y, color='purple')

Exemple 2 : spécifier les tailles des sous-parcelles individuelles

Le code suivant montre comment spécifier différentes tailles pour des sous-tracés individuels :

import matplotlib.pyplot as plt

#define subplots
fig, ax = plt.subplots(1, 2, gridspec_kw={'width_ratios': [3, 1]})
fig.tight_layout()

#define data
x = [1, 2, 3]
y = [7, 13, 24]

#create subplots
ax[0].plot(x, y, color='red')
ax[1].plot(x, y, color='blue')

Nous pouvons facilement modifier la taille des sous-traces en modifiant les valeurs dans l’argument width_ratios :

import matplotlib.pyplot as plt

#define subplots
fig, ax = plt.subplots(1, 2, gridspec_kw={'width_ratios': [1, 3]})
fig.tight_layout()

#define data
x = [1, 2, 3]
y = [7, 13, 24]

#create subplots
ax[0].plot(x, y, color='red')
ax[1].plot(x, y, color='blue')

Ressources additionnelles

Comment ajouter des titres aux tracés dans Matplotlib
Comment définir les plages d’axes dans Matplotlib
Comment définir les valeurs de l’axe X dans Matplotlib

Ajouter un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *