Tôi có một khung dữ liệu gấu trúc, người chỉ có các cột số và tôi đang cố gắng tạo một biểu đồ riêng cho tất cả các tính năng
ind group people value value_50 1 1 5 100 1 1 2 2 90 1 2 1 10 80 1 2 2 20 40 0 3 1 7 10 0 3 2 23 30 0Nhưng trong dữ liệu thực tế của tôi có hơn 50 cột, làm thế nào tôi có thể tạo một lô riêng cho tất cả chúng
Tôi đã thử
df.plot.hist( subplots = True, grid = True)Nó cho tôi một cốt truyện không rõ ràng chồng chéo.
Làm thế nào tôi có thể sắp xếp chúng bằng cách sử dụng pandas subplots = true. Ví dụ dưới đây có thể giúp tôi có được biểu đồ trong (2,2) cho bốn cột. Nhưng nó là một phương pháp dài cho tất cả 50 cột
fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10))Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc Pandas
Bàn luậnPandas has a tight integration with Matplotlib. You can plot data directly from your DataFrame using the plot() method.
Điều kiện tiên quyết: gấu trúc
Approach:
- Python đi kèm với rất nhiều gói hữu ích như gấu trúc, matplotlib, numpy, v.v. Để sử dụng DataFrame, chúng tôi cần thư viện gấu trúc và để vẽ các cột của DataFrame, chúng tôi yêu cầu matplotlib. Pandas có một sự tích hợp chặt chẽ với matplotlib. Bạn có thể vẽ dữ liệu trực tiếp từ DataFrame của mình bằng phương thức Plot (). & NBSP;
- Để vẽ nhiều cột dữ liệu trong khung đơn, chúng tôi chỉ cần chuyển danh sách các cột cho đối số y của hàm lô. Đưa ra dưới đây là cách tiếp cận của APROPER để làm như vậy cùng với việc thực hiện ví dụ.
- Nhập mô -đun
- Tạo hoặc tải dữ liệu
- Chuyển đổi sang DataFrame
Sử dụng phương thức Plot (), chỉ định một cột duy nhất dọc theo trục x và nhiều cột làm mảng dọc theo trục y.
Hiển thị đồ thị.
Dưới đây là một vài ví dụ minh họa cách tiếp cận ở trên để vẽ bội số các cột dữ liệu trong một khung dữ liệu.Bestsellers
Python3
Ví dụ 1:
Cơ sở dữ liệu: Bà tiêu bán chạy nhất
import pandas as pd
import matplotlib.pyplot as mp
data = pd.read_csv(df.plot.hist( subplots = True, grid = True) 0df.plot.hist( subplots = True, grid = True) 1
fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 6=fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 0fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 9=df.plot.hist( subplots = True, grid = True) 9fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 2fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 4import5=import7import8=pandas as pd0pandas as pd1fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1pandas as pd3pandas as pd4
pandas as pd5
Output:
data = df.plot.hist( subplots = True, grid = True) 4
Python3
Ví dụ 1:
Cơ sở dữ liệu: Bà tiêu bán chạy nhất
import pandas as pd
import9df.plot.hist( subplots = True, grid = True) 9matplotlib.pyplot as mp1fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1matplotlib.pyplot as mp3fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1import7import8
import9df.plot.hist( subplots = True, grid = True) 9matplotlib.pyplot as mp9fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1data 1fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1import7import8
import9df.plot.hist( subplots = True, grid = True) 9data 7fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1data 9fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1import7import8
import9df.plot.hist( subplots = True, grid = True) 9=5fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1=7fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1import7pd.read_csv(0
import matplotlib.pyplot as mp
fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 6=pd.read_csv(6fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 9=df.plot.hist( subplots = True, grid = True) 9pd.read_csv(8fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1df.plot.hist( subplots = True, grid = True) 00import8
import9df.plot.hist( subplots = True, grid = True) 13=df.plot.hist( subplots = True, grid = True) 15import8=pandas as pd0df.plot.hist( subplots = True, grid = True) 19fig, [(ax1,ax2),(ax3,ax4)] = plt.subplots(2,2, figsize = (20,10)) 1df.plot.hist( subplots = True, grid = True) 19pandas as pd4
pandas as pd5
Output: