Most Frequent Python Code Snippets
- https://towardsdatascience.com/a-simple-guide-to-beautiful-visualizations-in-python-f564e6b9d392
-
ggplot
andfivethirtyeight
are nice matplotlib styles.
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid') # darkgrid, white grid, dark, white and ticks
plt.rc('axes', titlesize=18) # fontsize of the axes title
plt.rc('axes', labelsize=14) # fontsize of the x and y labels
plt.rc('xtick', labelsize=13) # fontsize of the tick labels
plt.rc('ytick', labelsize=13) # fontsize of the tick labels
plt.rc('legend', fontsize=13) # legend fontsize
plt.rc('font', size=13) # controls default text sizes
plt.style.use("ggplot")
sns.set_palette('deep', 8, color_codes = True)
fig, ax = plt.subplots(nrows=1,ncols=2, figsize=(12, 5), tight_layout=True)
# seaborn
ax = sns.histplot(..., palette='Set2', linewidth=2) # seaborn will have either the color or palette parameters available (it depends on the plot)
#seaborn
ax.set(title='Barplot', xlabel='Nationality', ylabel='Average Rating')
from matplotlib.animation import FuncAnimation
from matplotlib import animation
from matplotlib import rc
rc('animation', html='jshtml')
anim = FuncAnimation(fig, change_plot, frn, fargs=(Z, plot), interval=1000 / fps)
# Close the figure, otherwise would show as duplicate below animation
plt.close()
display(anim)
mywriter = animation.PillowWriter(fps=fps)
anim.save('gif_name.gif',writer=mywriter)