<jupyter_start><jupyter_text>Pie Chart<jupyter_code>import matplotlib.pyplot as plt
import pandas as pd
# Bare minimum
values = [10, 20]
plt.pie(values)
plt.show()
values=[5,8,9,10]
colors=['green', 'orange', 'yellow', 'gray']
labels=['a','b','c','d']
explode= [0, 0, 0, 0.5] # dist from center

plt.pie(values,
        colors=colors,
        labels=labels,
        explode=explode,
        autopct="%1.1f%%", # format
        counterclock=True,
        shadow=True
)

plt.title("Pie Chart")
plt.show()<jupyter_output><empty_output><jupyter_text>From DataFrame<jupyter_code>df = pd.DataFrame({"mass": [0.330, 4.87, 5.97],"radius": [2439.7,6051.8,6378.1]},index=["Mercury","Venus","Earth"])
print(df)
plot = df.plot.pie(y="mass", figsize=(5, 5))
df['mass'].plot(kind='pie', figsize=(5,5))<jupyter_output><empty_output><jupyter_text>Bar ChartRecommended for categorical<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# Bare minimum
x = range(0, 5)
values = [5, 6, 5, 5, 4]

plt.bar(x, values)
left = ['a', 'b', 'c', 'd', 'e']
values = [5,6,5,5,4]
widths = [0.7,0.7,0.7,0.7,0.9]
colors = ['g', 'g', 'g', 'g', 'r']

# edge is where the key is located (a is on the left instead of center)
# hatch is the design

plt.bar(left, values, width=widths,color=colors, align="edge", hatch="o")
plt.show()<jupyter_output><empty_output><jupyter_text>From DataFrame<jupyter_code>np.random.seed(12348)
arr = np.random.rand(6, 4) # rand grid

df = pd.DataFrame(arr, 
                  index=['uk','monaco','czech','france','austria','italy'],
                  columns=pd.Index([2018, 2019, 2020, 2021], name='Country'))
df
df.plot.bar()
df.plot.bar(stacked=True)
df.plot.barh()  # horizontal
df.plot.barh(stacked=True, alpha=0.5)
df[2018].plot.bar()  # single col<jupyter_output><empty_output><jupyter_text>Bar<jupyter_code># mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
src = pd.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv")
# cross tabulate
ct = pd.crosstab(index=src['day'], columns=src['size'])
ct
ct.sum(axis=1)
ct = ct.div(ct.sum(axis=1), axis=0) # divide size by sum of size to get 100% chart ?
# display
df = pd.DataFrame(ct, 
                  index=pd.Index(['Thur','Fri','Sat','Sun'], name='day'), #cols
                  columns=pd.Index([1,2,3,4,5,6], name='size'))  # size

df.plot.bar(stacked=True)<jupyter_output><empty_output><jupyter_text>SubPlots<jupyter_code>import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from numpy.random import randn
arr = np.array([1, 2, 3, 4])

fig = plt.figure()

# first two args is the grid and the last arg is the index.
# subplots are in a sense placed one on top of another
# (figure doesn't control subplots).
ax1 = fig.add_subplot(2, 2, 1) # cols, rows, subplot num
ax3 = fig.add_subplot(2, 2, 3)

plt.plot(randn(50).cumsum(), 'k--')  # plots onto the most recently added subplot
ax1.hist(randn(100), bins=20, color='k', alpha=.3) # modify existing plots
ax2 = fig.add_subplot(2, 2, 2)
ax2.scatter(np.arange(30), np.arange(30) + 3 * randn(30))
fig<jupyter_output><empty_output><jupyter_text>SubPlots (2)<jupyter_code>import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from numpy.random import randn
fig, axes = plt.subplots(2, 3) # y * x
axes[0, 0].hist(randn(500), bins=50, color='k', alpha=.5)
axes[0, 1].hist(randn(500), bins=50, color='k', alpha=.5)
axes[0, 2].hist(randn(500), bins=50, color='k', alpha=.5)
axes[1, 0].hist(randn(500), bins=50, color='k', alpha=.5)
axes[1, 1].hist(randn(500), bins=50, color='k', alpha=.5)
axes[1, 2].hist(randn(500), bins=50, color='k', alpha=.5)

plt.subplots_adjust(wspace=0, hspace=0)<jupyter_output><empty_output><jupyter_text>Bar Plot (series)<jupyter_code>import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from numpy.random import randn
data = pd.Series(np.random.rand(16), index=list("abcdefghijklmnop"))

fig, axis = plt.subplots(2, 1)

data.plot.bar(ax=axis[0], alpha=.5)
data.plot.barh(ax=axis[1], color='k', alpha=0.5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1824390243902439, 'fraction_numerical': 0.04951219512195122, 'mean_word_length': 5.223065250379363, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '31854', 'license': 'CC0-1.0', 'n_tokens_mistral': 1784, 'n_tokens_neox': 1629, 'n_words': 361, 'path': 'classwork/03_01_2021/03_01_2021.ipynb', 'repo_name': 'Katsute/Baruch-CIS-4170-Assignments', 'size': '4100'}