Python 熊猫:堆积点直方图

Python 熊猫:堆积点直方图,python,pandas,histogram,Python,Pandas,Histogram,基本上是标题。我想做一个柱状图,在柱状图中用一列堆叠的点代替条形图。对于这个特定的问题有一个答案,但我想继续讨论python 非常感谢您的帮助:) 编辑:添加到图像的链接 我不太清楚你所说的“带点的直方图”到底是什么意思,但你所描述的听起来让我想起 此处有Swarmlot文档: 在看到您的编辑后,似乎这更像是您想要的: import matplotlib.pyplot as plt import numpy as np from collections import Counter data

基本上是标题。我想做一个柱状图,在柱状图中用一列堆叠的点代替条形图。对于这个特定的问题有一个答案,但我想继续讨论python

非常感谢您的帮助:)

编辑:添加到图像的链接
我不太清楚你所说的“带点的直方图”到底是什么意思,但你所描述的听起来让我想起

此处有Swarmlot文档:

在看到您的编辑后,似乎这更像是您想要的:

import matplotlib.pyplot as plt
import numpy as np
from collections import Counter

data = np.random.randint(10, size=100)
c = Counter(data)
d = dict(c)
l = []

for i in data:
    l.append(d[i])
    d[i] -= 1

plt.scatter(data, l)
plt.show()

我个人认为Swarmlot看起来好多了,但不管你的船是怎么浮起来的。

在matplotlib或其衍生产品(我熟悉)中,没有现成的东西可以做到这一点。幸运的是,
pandas.Series.value\u counts()
为我们做了很多繁重的工作:

import numpy
from matplotlib import pyplot
import pandas

numpy.random.seed(0)
pets = ['cat', 'dog', 'bird', 'lizard', 'hampster']
hist = pandas.Series(numpy.random.choice(pets, size=25)).value_counts()
x = []
y = []
for p in pets:
    x.extend([p] * hist[p])
    y.extend(numpy.arange(hist[p]) + 1)

fig, ax = pyplot.subplots(figsize=(6, 6))
ax.scatter(x, y)
ax.set(aspect='equal', xlabel='Pet', ylabel='Count')
这给了我:


恐怕我不是这个意思。我想要的是一个柱状图,在柱状图中,条形图被点条代替,这样一个高度为3的条形图就会显示出一堆3个点。我已经编辑并添加了一张图片。@jasikevicius23据我所知,这不是或的特征。这也许可以通过从直方图中提取数据并将其重塑为散点图来实现。那行吗?行!这正是我想要的。可惜没有更简单的方法。谢谢
import numpy
from matplotlib import pyplot
import pandas

numpy.random.seed(0)
pets = ['cat', 'dog', 'bird', 'lizard', 'hampster']
hist = pandas.Series(numpy.random.choice(pets, size=25)).value_counts()
x = []
y = []
for p in pets:
    x.extend([p] * hist[p])
    y.extend(numpy.arange(hist[p]) + 1)

fig, ax = pyplot.subplots(figsize=(6, 6))
ax.scatter(x, y)
ax.set(aspect='equal', xlabel='Pet', ylabel='Count')