Ontwikkel Matplotlib Visualisaties met Automatische Thematische Kleurenpaletten
description
Met deze prompt kun je efficiënte en esthetisch aantrekkelijke visualisaties maken die automatisch de juiste kleuren gebruiken passend bij je thema. Dit bespaart tijd en zorgt voor consistente, professionele grafieken die beter aansluiten bij je inhoud en doelpubliek.
prompt
Help me een Matplotlib visualisatie te maken voor mijn dataset: <beschrijving van je dataset>. Ik wil dat de kleuren automatisch worden geselecteerd uit een thematisch kleurenpalet dat past bij mijn onderwerp: <thema van de visuali ...
try_prompt
generate_helper
disclaimerOnPageApi
tags
ai_answers
provider: openai
model: gpt-4.1-nano
no_answer_for_language
error: Generation failed [openai] prompt_id=3647 locale=nl err=OpenAI connection/timeout | Generation failed [openai] prompt_id=3647 locale=en err=OpenAI connection/timeout | Generation failed [openai] prompt_id=3647 locale=de err=OpenAI connection/timeout | Generation failed [openai] prompt_id=3647 locale=fr err=OpenAI connection/timeout | Generation failed [openai] prompt_id=3647 locale=pt err=OpenAI connection/timeout | Generation failed [openai] prompt_id=3647 locale=es err=OpenAI connection/timeout | Generation failed [openai] prompt_id=3647 locale=zh err=OpenAI connection/timeout
provider: deepseek
model: deepseek-chat
Hier is een complete, direct uitvoerbare Python-code met automatisch kleurenpalet voor technologie-thema:
```python
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.colors import LinearSegmentedColormap
from datetime import datetime
# Voorbeeld dataset (vervang dit met jouw eigen data)
def create_sample_data():
maanden = ['Jan', 'Feb', 'Mrt', 'Apr', 'Mei', 'Jun',
'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec']
categorieën = ['Smartphones', 'Laptops', 'Wearables', 'Smart Home', 'Drones']
data = {}
for categorie in categorieën:
data[categorie] = np.random.randint(1000, 10000, size=len(maanden))
return pd.DataFrame(data, index=maanden)
# Automatisch kleurenpalet generator voor technologie-thema
def generate_tech_colors(n_colors, saturation=0.6, lightness=0.7, contrast=1.0):
"""
Genereert een modern technologie kleurenpalet
Parameters:
n_colors: aantal kleuren nodig
saturation: verzadiging (0.0 - 1.0)
lightness: helderheid (0.0 - 1.0)
contrast: contrastniveau (0.5 - 2.0)
"""
# Basis technologie kleuren (blauw, paars, groen, cyaan, magenta)
base_colors = [
(0.1, 0.3, 0.8), # Blauw
(0.6, 0.2, 0.8), # Paars
(0.2, 0.7, 0.4), # Groen
(0.0, 0.6, 0.6), # Cyaan
(0.8, 0.2, 0.6) # Magenta
]
colors = []
for i in range(n_colors):
base_color = base_colors[i % len(base_colors)]
# Pas verzadiging en helderheid aan
r, g, b = base_color
h, l, s = rgb_to_hls(r, g, b)
# Pas parameters aan
s = max(0.1, min(1.0, saturation))
l = max(0.3, min(0.9, lightness * l))
# Terug naar RGB
r, g, b = hls_to_rgb(h, l, s)
# Pas contrast aan
r = max(0.0, min(1.0, (r - 0.5) * contrast + 0.5))
g = max(0.0, min(1.0, (g - 0.5) * contrast + 0.5))
b = max(0.0, min(1.0, (b - 0.5) * contrast + 0.5))
colors.append((r, g, b))
return colors
# Hulpfuncties voor kleurconversie
def rgb_to_hls(r, g, b):
maxc = max(r, g, b)
minc = min(r, g, b)
l = (minc + maxc) / 2.0
if minc == maxc:
return 0.0, l, 0.0
if l <= 0.5:
s = (maxc - minc) / (maxc + minc)
else:
s = (maxc - minc) / (2.0 - maxc - minc)
rc = (maxc - r) / (maxc - minc)
gc = (maxc - g) / (maxc - minc)
bc = (maxc - b) / (maxc - minc)
if r == maxc:
h = bc - gc
elif g == maxc:
h = 2.0 + rc - bc
else:
h = 4.0 + gc - rc
h = (h / 6.0) % 1.0
return h, l, s
def hls_to_rgb(h, l, s):
if s == 0.0:
return l, l, l
if l <= 0.5:
m2 = l * (1.0 + s)
else:
m2 = l + s - (l * s)
m1 = 2.0 * l - m2
r = _hue_to_rgb(m1, m2, h + 1.0/3.0)
g = _hue_to_rgb(m1, m2, h)
b = _hue_to_rgb(m1, m2, h - 1.0/3.0)
return r, g, b
def _hue_to_rgb(m1, m2, h):
h = h % 1.0
if h < 1.0/6.0:
return m1 + (m2 - m1) * h * 6.0
elif h < 0.5:
return m2
elif h < 2.0/3.0:
return m1 + (m2 - m1) * (2.0/3.0 - h) * 6.0
else:
return m1
# Hoofdvisualisatie functie
def create_sales_visualization(df, saturation=0.4, lightness=0.8, contrast=0.8):
"""
Maakt een staafdiagram van maandelijkse verkoopcijfers
Parameters:
df: DataFrame met verkoopdata
saturation: verzadiging (0.0 - 1.0)
lightness: helderheid (0.0 - 1.0)
contrast: contrast (0.5 - 2.0)
"""
n_categories = len(df.columns)
# Genereer automatische kleuren
colors = generate_tech_colors(n_categories, saturation, lightness, contrast)
# Maak de visualisatie
fig, ax = plt.subplots(figsize=(14, 8))
# Staafdiagram maken
bar_width = 0.8 / n_categories
x_pos = np.arange(len(df.index))
for i, category in enumerate(df.columns):
offset = (i - n_categories/2) * bar_width + bar_width/2
ax.bar(x_pos + offset, df[category], bar_width,
label=category, color=colors[i], alpha=0.9,
edgecolor='white', linewidth=0.5)
# Styling
ax.set_xlabel('Maanden', fontsize=12, fontweight='bold')
ax.set_ylabel('Verkoopcijfers', fontsize=12, fontweight='bold')
ax.set_title('Maandelijkse Verkoopcijfers - Technologie Producten\nModern Kleurenpalet',
fontsize=16, fontweight='bold', pad=20)
ax.set_xticks(x_pos)
ax.set_xticklabels(df.index)
ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
# Grid en achtergrond
ax.grid(True, alpha=0.3, linestyle='--')
ax.set_axisbelow(True)
ax.set_facecolor('#f8f9fa')
# Randen opmaken
for spine in ax.spines.values():
spine.set_visible(False)
plt.tight_layout()
return fig, ax
# Gebruik voorbeeld:
if __name__ == "__main__":
# Laad of creëer dataset
sales_data = create_sample_data()
# Maak visualisatie met pastelkleuren (lage verzadiging)
fig, ax = create_sales_visualization(
sales_data,
saturation=0.3, # Zeer lage verzadiging voor pastel effect
lightness=0.85, # Hoge helderheid
contrast=0.7 # Laag contrast voor zachte kleuren
)
plt.show()
# Optie: sla figuur op
# fig.savefig('tech_sales_visualization.png', dpi=300, bbox_inches='tight')
```
Deze code bevat:
1. **Automatisch kleurenpalet** met technologie-thema (blauw, paars, groen, cyaan, magenta)
2. **Aanpasbare parameters** voor verzadiging, helderheid en contrast
3. **Pastelkleuren optie** via lage verzadiging en hoge helderheid
4. **Professionele styling** met grid, achtergrondkleur en legenda
5. **Direct uitvoerbaar** met voorbeelddata
Pas de parameters `saturation`, `lightness` en `contrast` aan om verschillende kleureffecten te krijgen. Voor pastelkleuren gebruik je lage verzadiging (0.2-0.4) en hoge helderheid (0.8-0.9).