2825 explained code solutions for 75 technologies


python-matplotlibHow to plot data from CSV


import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("/var/www/examples/data.csv")
plt.plot(df.a, df.b)
plt.show()ctrl + c
import matplotlib.pyplot as plt

loads Matplotlib module to use plotting capabilities

import pandas as pd

load Pandas module

pd.read_csv

read specified CSV file

/var/www/examples/data.csv

path to sample CSV file

.plot(

plot specified data

df.a, df.b

use column a data for X axis and b column data for Y axis

.show()

render chart in a separate window


How to plot data from CSV, python matplotlib

Usage example

import pandas as pd
import matplotlib.pyplot as plt

with open('/var/www/examples/data.csv', 'r') as f:
  print(f.read()) # print CSV file contents

df = pd.read_csv("/var/www/examples/data.csv")

plt.plot(df.a, df.b)
plt.show()
output
a,b
1,4
2,3
3,6