Last active
December 22, 2022 17:55
-
-
Save rejgan318/3adb0f7701349e5e29a3d2b84b2ca5f4 to your computer and use it in GitHub Desktop.
[Python] [Seaborn] #Seaborn#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
df = pd.DataFrame() | |
df['X'] = [1, 2, 1, 2] | |
df['Y'] = [0, -1, 2, 1] | |
df['GRP'] = ['HOT', 'COLD', 'COLD', 'HOT'] | |
ax = sns.scatterplot(data=df, hue='GRP', x='X', y='Y') | |
ax.add_patch(plt.Circle(xy=(0, 0), radius=2, color='red', fill=False)) | |
ax.text(0, 0, 'Hello!') | |
ax.set(xlim=(-4, 4), ylim=(-4, 4), title='Points with circle') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Несколько графиков одновременно | |
# https://stackoverflow.com/questions/52308749/how-do-i-create-a-multiline-plot-using-seaborn | |
num_rows = 20 | |
years = list(range(1990, 1990 + num_rows)) | |
data_preproc = pd.DataFrame({ | |
'Year': years, | |
'A': np.random.randn(num_rows).cumsum(), | |
'B': np.random.randn(num_rows).cumsum(), | |
'C': np.random.randn(num_rows).cumsum(), | |
'D': np.random.randn(num_rows).cumsum()}) | |
sns.lineplot(x='Year', y='value', hue='variable', | |
data=pd.melt(data_preproc, id_vars=['Year'])) | |
# Можно использовать последовательно два или более вывода графиков из разных наборов данных | |
# https://stackoverflow.com/questions/65835962/how-to-draw-multiple-lines-with-seaborn | |
import random | |
import numpy as np | |
import seaborn as sns | |
mu, sigma = 0, 0.1 | |
s = np.random.normal(mu, sigma, 100) | |
mu1, sigma1 = 0.5, 1 | |
t = np.random.normal(mu1, sigma1, 100) | |
sns.lineplot(data= s, color = "red") | |
sns.lineplot(data= t, color ="blue") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment