首页 > 解决方案 > Formatting style for matplotlib: scatterplot histogram hybrid

问题描述

In an old standalone plotting package (sm) there was a style available for scatter plots which I found more appealing to the general style. It appears as each point looking almost like a histogram which stretches to the next point.

An example of a scatter plot using this style: Example

Matplotlib does have this style for histograms, but I'm wondering if there's a way to cheat the system to allow the style to work for scatter plots.

标签: pythonmatplotlib

解决方案


我认为一些混乱来自于所需的情节不是散点图这一事实。这是一个线图,线的形式为阶梯函数。

pyplot.step(x,y)您可以用或绘制阶跃函数plot(x,y, drawstyle="steps")

import matplotlib.pyplot as plt
import numpy as np; np.random.seed(42)

x = np.linspace(0,1)
y = np.random.rand(len(x))

fig, ax = plt.subplots()

ax.step(x,y)
# or
# ax.plot(x,y, drawstyle="steps")

plt.show()

在此处输入图像描述


推荐阅读