Cheat Sheet: Plotting with Matplotlib using Pandas

 

Cheat Sheet : Plotting with Matplotlib using Pandas

Plot Type
Description
Pandas Function
Example
Visual
Line PlotShows trends and changes over timeDataFrame.plot.line()
DataFrame.plot(kind = ‘line’)
df.plot(x=’year’, y=’sales’, kind=’line’)
Area PlotDisplays data series as filled areas, showing the relationship between themDataFrame.plot.area()
DataFrame.plot(kind = ‘area’)
df.plot(kind='area')
HistogramDisplays bars representing the data count in each interval/binSeries.plot.hist()
Series.plot(kind = ‘hist’, bins = n)
s.plot(kind='hist', bins=10)
df[‘age’].plot(kind='hist', bins=10)
Bar ChartDisplays data using rectangular barsDataFrame.plot.bar()
DataFrame.plot(kind = ‘bar’)
df.plot(kind='bar')
Pie ChartDisplays data as a circular plot divided into slices, representing proportions or percentages of a wholeSeries.plot.pie()
Series.plot(kind = ‘pie’)
DataFrame.plot.pie(y, labels)
DataFrame.plot(kind = ‘pie’)
s.plot(kind='pie’,autopct='%1.1f%%')
df.plot(x='Category',y='Percentage',kind='pie')
Box PlotDisplays the distribution of a dataset along with key statistical measuresDataFrame.plot.box()
DataFrame.plot(kind = ‘box’)
df_can.plot(kind='box')
Scatter PlotUses Cartesian coordinates to display values for two variablesDataFrame.plot.scatter()
DataFrame.plot(x, y, kind = ‘scatter’)
df.plot(x='Height', y='Weight', kind='scatter')

Cheat Sheet : Plotting directly with Matplotlib

Plot Type
Description
Matplotlib Function
Example
Visual
Line PlotShows trends and changes over timeplt.plot()plt.plot(x, y, color='red', linewidth=2)
Area PlotDisplay data series as filled areasplt.fill_between()plt.fill_between(x, y1, y2, color='blue', alpha=0.5)
HistogramDisplays bars representing the data count in each interval/binplt.hist()plt.hist(data, bins=10, color='orange', edgecolor='black')
Bar ChartDisplays data using rectangular barsplt.bar()plt.bar(x, height, color='green', width=0.5)
Pie ChartDisplays data as a circular plot divided into slices, representing proportions or percentages of a wholeplt.pie()plt.pie(sizes, labels=labels, colors=colors, explode=explode)
Box PlotDisplays the distribution of a dataset along with key statistical measuresplt.boxplot()plt.boxplot(data, notch=True)
Scatter PlotUses Cartesian coordinates to display values for two variablesplt.scatter()plt.scatter(x, y, color='purple', marker='o', s=50)
SubplottingCreating multiple plots on one figureplt.subplots()fig, axes = plt.subplots(nrows=2, ncols=2)
CustomizationCustomizing plot: adding labels, title, legend, gridVarious customizationplt.title('Title')
plt.xlabel('X Label')
plt.ylabel('Y Label')
plt.legend()
plt.grid(True)

Comments

Popular posts from this blog

Introduction to security frameworks and controls

Grid Search

Common cybersecurity terminology