【问题标题】:How to plot a boxplot using matplotlib with discontinuous y intervals on the y-axis?如何使用 matplotlib 在 y 轴上绘制不连续 y 间隔的箱线图?
【发布时间】:2014-04-18 10:33:47
【问题描述】:

我有以下数据集,我需要使用 matplotlib 为其生成箱线图:

[92,92,92,92,92,92,92,92,92,92,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95, 95,95,95,95,95,95,95,95,95,95,95]

但我希望将箱形图的 y 轴分为以下区间:[64000-277231、277231-380059、380059-827581、827581-1338451、1338451-2593146、2593146-4559994] 和 x - 轴以 1 为间隔进行划分,即 [1,2,3,4,5,6,7,8,9]。我是 matplotlib 的新手,必须完成这项工作,我也提到了这篇文章。我编写了以下脚本来绘制箱线图,但我无法使用不同的 matplotlib 结构(如 xticks、yticks 和 xlim 和 ylim)来实现上述功能。

import numpy as np
import matplotlib as mpl

# agg backend is used to create the output file as a .png file
mpl.use('agg')

import matplotlib.pyplot as plt

plt.suptitle('Bitrate vs Trials', fontsize=15)
plt.ylabel("Bitrate")   
plt.xlabel("Trials")    
fig_instance = plt.figure(1 , figsize=(9,6))
ax_instance = fig_instance.add_subplot(111)
bp = ax_instance.boxplot(bitRateList)
# save the figure
fig_instance.savefig('a.png',bbox_inches='tight')

如何为上面的列表绘制图表。

【问题讨论】:

    标签: python numpy matplotlib


    【解决方案1】:

    好像你想用log scale y轴,你可以试试

    ax_instance.set_yscale('log')
    

    【讨论】:

    • 我希望将 y 轴拆分为以下间隔,并使用这些间隔绘制绘图 - [64000-277231、277231-380059、380059-827581、827581-1338451、1338451-2593146 , 2593146-4559994]
    • @AnkitSablok 我计算了你前几个区间的自然对数值,对数结果接近线性值,所以我认为这是你要求的对数比例。
    • 你能解释一下“日志结果接近线性值”是什么意思吗,我无法理解
    • @AnkitSablok 我的意思是 [ln(64000), ln(277231), ln(380059), ln(827581), ln(1338451), ln(2593146), ln(4559994)] 就像一个线性系列。你从哪里得到这些数字的?
    • 是的,它是一个单调递增的序列,但我已经按顺序排列了数据
    猜你喜欢
    • 2019-11-04
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 2016-06-24
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    相关资源
    最近更新 更多