Plotsdecoratie
Stijl instellen
seaborn biedt de functie set_style() specifiek voor het instellen van de visuele stijl van grafieken. Deze functie vereist één verplichte parameter genaamd style. De parameter style accepteert verschillende vooraf gedefinieerde opties, die elk een unieke stijl vertegenwoordigen:
'white''dark''whitegrid''darkgrid''ticks'
Experimenteer gerust met deze opties:
12345678910import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Palet instellen
Een andere mogelijkheid is het aanpassen van de kleuren van grafiekelementen in seaborn met de functie set_palette(), waarbij de enige vereiste parameter palette centraal staat:
- Circulaire paletten:
'hls','husl'; - Perceptueel uniforme paletten:
'rocket','magma','mako', enzovoort; - Divergerende kleurpaletten:
'RdBu','PRGn', enzovoort; - Sequentiële kleurpaletten:
'Greys','Blues', enzovoort.
Je kunt meer ontdekken over verschillende paletten in het "Choosing color palettes" artikel.
1234567891011121314import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Context Instellen
Er is een andere functie in de seaborn-bibliotheek, set_context(). Deze beïnvloedt aspecten zoals de grootte van de labels, lijnen en andere elementen van de plot (de algemene stijl wordt niet beïnvloed).
De belangrijkste parameter is context, die een dict van parameters kan zijn of een string die de naam van een vooraf ingestelde set vertegenwoordigt.
De standaardwaarde voor context is 'notebook'. Andere beschikbare contexten zijn 'paper', 'talk' en 'poster', die in wezen geschaalde versies van de notebook-parameters zijn.
1234567891011121314151617import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Setting the context sns.set_context('paper') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Meer informatie is te vinden in de set_context() documentatie.
Swipe to start coding
- Gebruik de juiste functie om de stijl in te stellen op
'dark'. - Gebruik de juiste functie om het palet in te stellen op
'rocket'. - Gebruik de juiste functie om de context in te stellen op
'talk'.
Oplossing
Bedankt voor je feedback!
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
What are the differences between the available styles in `set_style()`?
Can you explain more about the different palette options in `set_palette()`?
How does changing the context with `set_context()` affect the appearance of my plots?
Awesome!
Completion rate improved to 3.85
Plotsdecoratie
Veeg om het menu te tonen
Stijl instellen
seaborn biedt de functie set_style() specifiek voor het instellen van de visuele stijl van grafieken. Deze functie vereist één verplichte parameter genaamd style. De parameter style accepteert verschillende vooraf gedefinieerde opties, die elk een unieke stijl vertegenwoordigen:
'white''dark''whitegrid''darkgrid''ticks'
Experimenteer gerust met deze opties:
12345678910import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Palet instellen
Een andere mogelijkheid is het aanpassen van de kleuren van grafiekelementen in seaborn met de functie set_palette(), waarbij de enige vereiste parameter palette centraal staat:
- Circulaire paletten:
'hls','husl'; - Perceptueel uniforme paletten:
'rocket','magma','mako', enzovoort; - Divergerende kleurpaletten:
'RdBu','PRGn', enzovoort; - Sequentiële kleurpaletten:
'Greys','Blues', enzovoort.
Je kunt meer ontdekken over verschillende paletten in het "Choosing color palettes" artikel.
1234567891011121314import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Context Instellen
Er is een andere functie in de seaborn-bibliotheek, set_context(). Deze beïnvloedt aspecten zoals de grootte van de labels, lijnen en andere elementen van de plot (de algemene stijl wordt niet beïnvloed).
De belangrijkste parameter is context, die een dict van parameters kan zijn of een string die de naam van een vooraf ingestelde set vertegenwoordigt.
De standaardwaarde voor context is 'notebook'. Andere beschikbare contexten zijn 'paper', 'talk' en 'poster', die in wezen geschaalde versies van de notebook-parameters zijn.
1234567891011121314151617import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Setting the context sns.set_context('paper') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Meer informatie is te vinden in de set_context() documentatie.
Swipe to start coding
- Gebruik de juiste functie om de stijl in te stellen op
'dark'. - Gebruik de juiste functie om het palet in te stellen op
'rocket'. - Gebruik de juiste functie om de context in te stellen op
'talk'.
Oplossing
Bedankt voor je feedback!
single