用pyhton画带饼图的柱状图(bar with pie)

用pyhton画带饼图的柱状图(bar with pie)

import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import matplotlib as mpl
mpl.rcParams['font.family'] = 'times new roman'
# 设置字体
# plt.rcParams['font.family'] = ['Times New Roman']
data = {
    'Class': ['5UTR', 'TSS', 'CDS', 'TTS', '3UTR'],
    'Count': [431, 783, 5801, 595, 2391]
}

df = pd.DataFrame(data)

# 设置颜色
colors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd']

# 绘制柱状图
fig, ax = plt.subplots(figsize=(10, 6))
bars = ax.bar(df['Class'], df['Count'], color=colors[:len(df)])

ax.set_xlabel('Class', fontsize=12)
ax.set_ylabel('Count', fontsize=12)

# 旋转 x 轴标签
plt.xticks(rotation=25)
# plt.subplots_adjust(bottom=0.183)
# 添加数值标签
for bar in bars:
    height = bar.get_height()
    ax.text(bar.get_x() + bar.get_width() / 2, height, height, ha='center', va='bottom')

# 创建新的 Axes 对象,并绘制饼状图
ax2 = inset_axes(ax, width="40%", height="40%", loc='upper right')
ax2.pie(df['Count'], radius=1, labeldistance=0.6, colors=colors[:len(df)])

# plt.savefig('class.pdf')
# 显示图形
plt.show()

更简单的方法:利用微生信

微生信

很好用的网站,推荐推荐

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进阶媛小吴

规则简单易懂,粗暴却完美!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值