Python matplotlib
Posted on 05/09/2018, in Data Science, Python.Install & Doc
pip install matplotlib- Documentation (use search function)
import matplotlib.pyplot as plt
Use?
- Grades follows distribution:
plt.hist()(histogram)
Basic plots
import matplotlib.pyplot as plt
plt.plot(year,pop)
plt.show()
- Plot:
plt.plot() - Show plot:
plt.show() - Plot điểm (no line):
plt.scatter() - Change scale:
plt.xscale('log')(cf) - Clear up plot:
plt.clf plt.grid(True): show gridplt.text(x, y , 'Text'): display'Text'tại tạo độ(x,y)- Only 1 arg:
plt.plot(y)consider the index asxinput
Scatter
- Plot điểm rời rạc
plt.scatter(x, y, s = np.array(pop), c = col)c = list-of-color: đổi colors = np.array(pop): chuyển sang arrayalpha = 0.8: apacity of the bubble
Histogram
- Use:
plt.hist(values, bins = 3)and thenplt.show() bins: chia thành mấy cụm cho dữ liệu đầu vào làvaluesđể thể hiện coi cụm nào có nhiều thằng nhất.
Customization
- Labels:
plt.xlabel('Year'),plt.ylabel() - Title:
plt.title() - Ticks:
plt.yticks([0,2,3],['0','2B','4B')Có sự tương ứng giữa 2 cái[], cái sau hiển thị thay chỗ tọa độ ghi trong cái trước.