import numpy as np
import matplotlib.pyplot as plt
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
x=range(1,6)
y=[1,4,6,8,4]
plt.fill_between(x, y)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
x=range(1,15)
y=[1,4,6,8,4,5,3,2,4,1,5,6,8,7]
plt.fill_between( x, y, color="skyblue", alpha=0.4)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
x=range(1,15)
y=[1,4,6,8,4,5,3,2,4,1,5,6,8,7]
plt.fill_between( x, y, color="skyblue", alpha=0.2)
plt.plot(x, y, color="Slateblue", alpha=0.6)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
x=range(1,15)
y=[1,4,6,8,4,5,3,2,4,1,5,6,8,7]
plt.fill_between( x, y, color="skyblue", alpha=0.3)
plt.plot(x, y, color="skyblue")
plt.title("An area chart", loc="left")
plt.xlabel("Value of X")
plt.ylabel("Value of Y")
plt.show()
import numpy as np
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
# Create data
my_count=["France","Australia","Japan","USA","Germany","Congo","China","England","Spain","Greece","Marocco","South Africa","Indonesia","Peru","Chili","Brazil"]
df = pd.DataFrame({
"country":np.repeat(my_count, 10),
"years":list(range(2000, 2010)) * 16,
"value":np.random.rand(160)
})
# Create a grid and initialize
g = sns.FacetGrid(df, col='country', hue='country', col_wrap=4, )
# Add line
g = g.map(plt.plot, 'years', 'value')
# Fill area
g = g.map(plt.fill_between, 'years', 'value', alpha=0.2).set_titles("{col_name} country")
# Control title
g = g.set_titles("{col_name}")
# Add the title
plt.subplots_adjust(top=0.92)
g = g.fig.suptitle('Evolution of the value of stuff in 16 countries')
plt.show()
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style("whitegrid")
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
blue, = sns.color_palette("muted", 1)
x = np.arange(23)
y = np.random.randint(8, 20, 23)
fig, ax = plt.subplots()
ax.plot(x, y, color=blue, lw=3)
ax.fill_between(x, 0, y, alpha=.3)
ax.set(xlim=(0, len(x) - 1), ylim=(0, None), xticks=x)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
x=range(1,6)
y=[ [1,4,6,8,9], [2,2,7,10,12], [2,8,5,10,6] ]
plt.stackplot(x,y, labels=['A','B','C'])
plt.legend(loc='upper left')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
x=range(1,6)
y1=[1,4,6,8,9]
y2=[2,2,7,10,12]
y3=[2,8,5,10,6]
plt.stackplot(x,y1, y2, y3, labels=['A','B','C'])
plt.legend(loc='upper left')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
X = np.arange(0, 10, 1)
Y = X + 5 * np.random.random((5, X.size))
baseline = ["zero", "sym", "wiggle", "weighted_wiggle"]
# Draw four pictures
for n, v in enumerate(baseline):
if n<3 :
plt.tick_params(labelbottom='off')
plt.subplot(2 ,2, n + 1)
plt.stackplot(X, *Y, baseline=v)
plt.title(v)
plt.axis('tight', size=0.2)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
x=range(1,6)
y=[ [10,4,6,5,3], [12,2,7,10,1], [8,18,5,7,6] ]
pal = sns.color_palette("Set1")
plt.stackplot(x,y, labels=['A','B','C'], colors=pal, alpha=0.4 )
plt.legend(loc='upper right')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
x=range(1,6)
y=[ [10,4,6,5,3], [12,2,7,10,1], [8,18,5,7,6] ]
pal = ["#9b59b6", "#e74c3c", "#34495e", "#2ecc71"]
plt.stackplot(x,y, labels=['A','B','C'], colors=pal, alpha=0.4 )
plt.legend(loc='upper right')
plt.show()
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
df.plot.area();
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
data = pd.DataFrame({
'group_A':[1,4,6,8,9],
'group_B':[2,24,7,10,12],
'group_C':[2,8,5,10,6],
}, index=range(1,6))
# Convert raw data into percentage
data_perc = data.divide(data.sum(axis=1), axis=0)
plt.stackplot(range(1,6), data_perc["group_A"], data_perc["group_B"], data_perc["group_C"], labels=['A','B','C'])
plt.legend(loc='upper left')
plt.margins(0,0)
plt.title('100 % stacked area chart')
plt.show()
The blogger opened a new official account , I hope you can scan the code and pay attention , Thank you very much .
This article is from :https://github.com/holtzy/The-Python-Graph-Gallery/blob/master/PGG_notebook.py