import numpy as np import pandas as pd import matplotlib import matplotlib.pyplot as plt import mmviz matplotlib.style.use("mmviz") mmviz.scale_palette_mm("qual_fill") df = pd.read_csv("../data/diamonds.csv") bin_width = 500 bins = mmviz.create_bin_list(df['price'], bin_width) df = df.pivot(columns='cut', values="price") ax = df.plot.hist(stacked=True, bins=bins) ax.set_title("Distribtion of Diamond Price by Cut") mmviz.theme_mm(ax, "histogram") plt.xlabel("Price (bin width = 500)") mmviz.place_legend(plt, "Cut", 0.2) plt.savefig("./images/histogram_1", dpi=100) plt.show()
import numpy as np import pandas as pd import matplotlib import matplotlib.pyplot as plt import mmviz matplotlib.style.use("mmviz") mmviz.scale_palette_mm("qual_color") df = pd.DataFrame(np.random.randn(1000, 4), index=pd.date_range('1/1/2000', periods=1000), columns=list('ABCD')) df = df.cumsum() ax = df.plot() ax.set_title("Random Value Over Time") mmviz.theme_mm(ax, "line") plt.xlabel("Time") plt.ylabel("Value") mmviz.place_legend(plt, "Category", 0.15) plt.savefig("./images/series", dpi=100) plt.show()
import numpy as np import pandas as pd import matplotlib import matplotlib.pyplot as plt import mmviz matplotlib.style.use("mmviz") df = pd.read_csv("../data/diamonds.csv") ax = df[['cut', 'price']].boxplot(by="cut", column="price") ax.set_title("Distribtion of Price by Cut") mmviz.theme_mm(ax, "box") plt.xlabel("Cut") plt.ylabel("Price") plt.savefig("./images/box_1", dpi=100) plt.show()
import numpy as np import pandas as pd import matplotlib import matplotlib.pyplot as plt import mmviz matplotlib.style.use("mmviz") df = pd.read_csv("../data/diamonds.csv") df1 = df.groupby('clarity').size() df1.sort_values(ascending=False, inplace=True) ax = df1.plot.bar(rot=0) ax.set_title("Diamonds by Clarity") mmviz.theme_mm(ax, "bar") plt.xlabel("Clarity") plt.ylabel("Frequency") plt.savefig("./images/bar", dpi=100) plt.show()
cols = ["cyl", "mpg", "wt", "disp"] df_cyl_dict = { "Cyl 4": df.loc[df["cyl"] == 4, cols], "Cyl 6": df.loc[df["cyl"] == 6, cols], "Cyl 8": df.loc[df["cyl"] == 8, cols] } palette_iter = mmviz.get_palette_iter_mm("qual_fill") ax = None for key in df_cyl_dict: ax = df_cyl_dict[key].plot.scatter(x="wt", y="mpg", label=key, c=next(palette_iter), s=df_cyl_dict[key]["disp"], ax=ax, alpha=0.8) ax.set_title("Weight vs. Miles Per Gallon") mmviz.theme_mm(ax, "scatter") plt.xlabel("Car Weight") plt.ylabel("Miles Per Gallon") mmviz.place_legend(plt, "Cylinder", 0.2) plt.savefig("./images/scatter", dpi=100) plt.show()
import numpy as np import pandas as pd import matplotlib import matplotlib.pyplot as plt import mmviz matplotlib.style.use("mmviz") df = pd.read_csv("../data/diamonds.csv") df1 = df.groupby('clarity').size() df1.sort_values(ascending=True, inplace=True) ax = df1.plot.barh(rot=0) ax.set_title("Diamonds by Clarity") mmviz.theme_mm(ax, "bar-horizontal") plt.xlabel("Clarity") plt.ylabel("Frequency") plt.savefig("./images/bar", dpi=100) plt.show()