Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Final Challenge | Plot Customization
First Dive into seaborn Visualization

book
Final Challenge

Tehtävä

Swipe to start coding

This is the right time for the final task of drawing a plot based on the material we have learned in this course. After completing this task, you will definitely be ready to create cool and colorful graphics for your future projects 🥳.

  1. Import the seaborn with sns alias.

  2. Import the matplotlib.pyplot with plt alias.

  3. Import the pandas with pd alias.

  4. Read the file.

  5. Set blue color for boy, pink for girl values.

  6. Set a histplot variable with histplot's binwidth = 0.1, data = df.

  7. Set the title 'Yummy fish!'.

  8. Set the xlabel 'Kilos of fish'.

  9. Set the context paper.

  10. Set the unique style: 'axes.facecolor' - 'white', 'figure.facecolor' - 'black', 'axes.labelcolor' - 'white', 'xtick.color':'white', 'ytick.color':'white'.

  11. Show the plot.

Ratkaisu

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/final_chlldg.csv')
colors = {'boy':'blue', 'girl':'pink'}
g = sns.histplot(x = 'kilos', hue = 'gender', palette = colors, data = df, binwidth = 0.1)
g.set_title('Yummy fish!', color = 'white')
g.set(xlabel = 'Kilos of fish')
sns.set_context('paper')
sns.set_style('darkgrid', {'axes.facecolor':'white', 'figure.facecolor':'black', 'axes.labelcolor':'white', 'xtick.color':'white', 'ytick.color':'white'})
plt.show()

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 6
single

single

# Import libraries needed
___
___
___

# Read the file
df = ___('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/final_chlldg.csv')

# Set colors for the hue
colors = {'___ ':'___', '___': '___'}

# Set plot value and binwidth
g = ___(x = 'kilos', hue = 'gender', palette = ___, ___ = ___, ___ = 0.1)

# Set the title
___.___('___', color = 'white')

# Set name to xlabel
___.___(___)

# Set the context
___.___('paper')

# Set the unique style
___('darkgrid', {'axes.facecolor':'white', '___':'black', 'axes.___':'white', 'xtick.___':'___', 'ytick.color':'___'})
# Show the plot
___

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt