相关疑难解决方法(0)

如何强制Y轴只在Matplotlib中使用整数?

我正在使用matplotlib.pyplot模块绘制直方图,我想知道如何强制y轴标签只显示整数(例如0,1,2,3等)而不是小数(例如0,0.5) ,1,1.5,2.等).

我正在查看指导说明,并怀疑答案位于matplotlib.pyplot.ylim附近,但到目前为止,我只能找到设置最小和最大y轴值的东西.

def doMakeChart(item, x):
    if len(x)==1:
        return
    filename = "C:\Users\me\maxbyte3\charts\\"
    bins=logspace(0.1, 10, 100)
    plt.hist(x, bins=bins, facecolor='green', alpha=0.75)
    plt.gca().set_xscale("log")
    plt.xlabel('Size (Bytes)')
    plt.ylabel('Count')
    plt.suptitle(r'Normal Distribution for Set of Files')
    plt.title('Reference PUID: %s' % item)
    plt.grid(True)
    plt.savefig(filename + item + '.png')
    plt.clf()
Run Code Online (Sandbox Code Playgroud)

python matplotlib axis-labels

49
推荐指数
3
解决办法
5万
查看次数

如何强制matplotlib只显示Y轴上的整数

我可视化的数据只有在整数时才有意义.

即,就我正在分析的信息的背景而言,记录的0.2是没有意义的.

如何强制matplotlib仅使用Y轴上的整数.即1,100,5等?不是0.1,0.2等

for a in account_list:
    f = plt.figure()
    f.set_figheight(20)
    f.set_figwidth(20)
    f.sharex = True
    f.sharey=True

    left  = 0.125  # the left side of the subplots of the figure
    right = 0.9    # the right side of the subplots of the figure
    bottom = 0.1   # the bottom of the subplots of the figure
    top = 0.9      # the top of the subplots of the figure
    wspace = 0.2   # the amount of width reserved for blank space between subplots …
Run Code Online (Sandbox Code Playgroud)

python visualization

6
推荐指数
4
解决办法
9048
查看次数

更改 Pandas/Matplotlib 直方图中标签的 x 轴顺序?

假设我有一列中包含离散值的 Pandas 数据框。

import pandas as pd

data = ['A']*2 + ['C']*3 + ['B']* 1
print(data)
# ['A', 'A', 'C', 'C', 'C', 'B']

my_df = pd.DataFrame({'mycolumn': data})
print(my_df)
#   mycolumn
# 0        A
# 1        A
# 2        C
# 3        C
# 4        C
# 5        B
Run Code Online (Sandbox Code Playgroud)

然后我创建一个直方图,显示这些值的频率。我使用 Pandas 内置函数hist(),它又依赖于 Matplotlib 直方图函数。

my_df.mycolumn.hist()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

现在,如何更改 X 轴上标签的顺序以具有特定顺序?例如,我希望 x 轴具有特定顺序的标签:C, A, B,而不是A, C, B如图所示。

另外,如何将 y 轴更改为整数而不是浮点数?频率值是离散计数。

python matplotlib pandas

1
推荐指数
1
解决办法
1321
查看次数

标签 统计

python ×3

matplotlib ×2

axis-labels ×1

pandas ×1

visualization ×1