import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 35, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]
men_std = [1, 3, 4, 1, 2]
women_std = [3, 5, 2, 3, 3]
width = 0.35 # the width of the bars: can also be len(x) sequence
fig, ax = plt.subplots()
ax.bar(labels, men_means, width, yerr=men_std, label='Men')
ax.bar(labels, women_means, width, yerr=women_std, bottom=men_means,
label='Women')
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.legend()
plt.show()
For useful examples, visit https://matplotlib.org/2.0.2/examples/index.html
# Plot y=x^2
import numpy as np
x = np.linspace (0,2,100)
fig, ax = plt.subplots()
ax.plot (x,x**2)
ax.set_xlabel("x")
ax.set_ylabel("y=x^2")
plt.show()
This example is used to show how to read regular data files and plot data in jupty notebook The key is that you need to import pandas as pd to read text files. Visit this website for more info http://awesci.com/reading-and-plotting-data-in-jupyter-notebook/ pd.read_csv function should be familiar, arguments as header=None, skiprows=1, you may use that.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
filename ='data_file/Au_15nm_20nm_MieNF_JC.dat'
data=pd.read_csv(filename,sep='\t',skiprows=1,header=None).values
data.shape
(601, 3)
lamda = data[:,0]
qext1_15nm = data[:,1]
qext2_20nm = data[:,2]
plt.plot(lamda, qext2_20nm,"r-")
plt.plot(lamda,qext1_15nm,"b-")
ax.set_xlabel("lamda")
ax.set_ylabel("Qext")
plt.show()