Blog

Python Visualization Cheatsheet

featured-image
data science terminologies data visualization machine learning pandas python

Python Visualization Cheatsheet

Importing Matplotlib

import matplotlib.pyplot as plt

Line Plot

In [ ]:

plt.plot(x, y, label=’label’)

plt.xlabel(‘x-axis’)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt. legend ()

plt.show()

 

Scatter Plot

In [ ]:

plt.scatter(x, y, label=’label’)

plt.xlabel(‘x-axis’)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt. legend ()

plt.show()

 

Bar Plot

In [ ]:

plt.bar(x, y, label=’label’)

plt.xlabel(‘x-axis’)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt. legend ()

plt.show()

Histogram

In [ ]:

plt.hist(data, bins=10)

plt.xlabel(‘x-axis’)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Box Plot

In [ ]:

plt.boxplot (data)

plt.xlabel(‘x-axis’)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Pie Chart

In [ ]:

plt.pie(data, labels=labels)

pit.title(‘Title’)

plt.show()

Importing Seaborn

import seaborn as sns

Line Plot

In [ ]:

sns.lineplot (x=x, y=y)

plt.xlabel (‘x-axis”)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Scatter Plot

In [ ]:

sns.scatterplot (x=x, y=y)

plt.xlabel (‘x-axis”)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Bar Plot

In [ ]:

sns.barplot (x=x, y=y)

plt.xlabel (‘x-axis”)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Histogram

In [ ]:

sns.histplot (data, bins=10)

plt.xlabel (‘x-axis”)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Box Plot

In [ ]:

sns.boxplot (data)

plt.xlabel (‘x-axis”)

pIt.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Heatmap

In [ ]:

sns.heatmap (data, annot=True)

pit.title(‘Title’)

plt.show()

Importing Plotly

import plotly.graph_objects as go

Line Plot

In [ ]:

fig = go.Figure ()

fig.add_trace (go.Scatter (x=x, y=y, name=’label’))

fig.update_layout (xaxis_title=’x-axis’, , yaxis_title=’y-axis’, title= ‘Title’)

fig.show()

Scatter Plot

In [ ]:


fig = go.Figure ()

fig. add_trace(go.Scatter (x=x, y=y, mode=’markers’ , name= ‘label’))

fig.update_layout (xaxis_title=’x-axis’, yaxis_title=’y-axis’, title=’Title”)

fig.show()

Bar Plot

In [ ]:

fig = go. Figure ()

fig. add_trace (go.Bar(x=x, y=y, name=’label’))

fig.update_layout (xaxis_title=’x-axis’, yaxis_title=’y-axis’, title=’Title”)

fig.show()

Histogram

In [ ]:

fig = go.Figure ()

fig. add_trace(go.Histogram(x=data, nbins×=10))

fig.update_layout (xaxis_title=’x-axis’, yaxis_title=’y-axis’, title=’Title’)

fig.show()

Box Plot

In [ ]:

fig = go.Figure ()

fig.add_trace(go.Box (y=data))

fig.update_layout(xaxis_title=’x-axis’, yaxis_title=’y-axis’, title=’Title’)

fig.show()

Heatmap

In [ ]:

fig = go.Figure (data=go.Heatmap (z=data, ×=×_labels, y=y_labels))

fig.update layout(title=’Title’)

fig.show()

Plotting with Pandas

Line Plot

In [ ]:

df.plot(x=’×_column’, y=’y_column’, kind=’line’)

pit.xlabel(‘x-axis’)

pit.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Scatter Plot

In [ ]:

df.plot (x= ‘x_column’, y= ‘y_column’, kind=’scatter’)

pit.xlabel(‘x-axis’)

pit.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Bar Plot

In [ ]:

df.plot(x=’×_column’, y=’y_column’, kind=’bar’)

pit.xlabel(‘x-axis’)

pit.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Histogram

In [ ]:

df.plot.hist (column= ‘column_name’, bins=10)

pit.xlabel(‘x-axis’)

pit.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Box Plot

In [ ]:

df.plot.box ()

pit.xlabel(‘x-axis’)

pit.ylabel(‘y-axis’)

pit.title(‘Title’)

plt.show()

Leave your thought here

Your email address will not be published. Required fields are marked *

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare