python分段绘制直方图,python绘制多个直方图

使用Python批量绘制DataFrame中每个变量的直方图,通过循环遍历列名,利用matplotlib库一次绘制多个直方图,每个直方图包含标题、标签和X、Y轴。代码示例展示了如何组织子图并去除多余的轴。
摘要由CSDN通过智能技术生成

I have a dataframe X with 30 variables, v1, v2 ... v30 and

col_name=[v1,v2.....v30]

For each variable, I want to plot the histogram to understand the variable distribution. However, it is too manual to write code to plot one by one, can I have something like a for loop to draw 30 histograms one under another at one go?

For example:

for i in range(30):

hist(np.array(X[col_name[i]]).astype(np.float),bins=100,color='blue',label=col_name[i],normed=1,alpha=0.5)

How can I do that? Like one page of graphs (each with title and label) so that I can scroll down to read.

解决方案

You could do something like this:

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

np.random.normal(0, 10)

df = pd.DataFrame({

'v1': np.random.norm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值