python - Gnuplot(或 matplotlib): create non-bar chart with categories on x-axis

标签 python graph matplotlib gnuplot

我想使用 gnuplot(或 matplotlib,如果需要)创建一个像这样的图表,但我不知道是否/如何完成:

rough outline of what the graph should look like

当然,这只是一个粗略的草图。重要的是我需要绘制成对的值(在这个例子中,每对由一个红点和一个蓝点组成)。每对中的一个项目是单个值,另一个应该显示一系列值(我的想法是用误差线绘制平均值以指示范围的最大值和最小值,但我愿意接受更好的想法) . x 轴除了给出各种类别的名称外没有其他用途——重要的是 y 值。

我很确定我可以使用直方图创建这样的东西(值对和 x 类别),但我觉得在这种情况下方框是错误的。

到目前为止我得到了什么:我有这个 gnuplot 命令:

plot 'TEST.out' using 0:2:3:xticlabel(1) w errorbars pt 7 notitle

与此数据文件一起使用(类别名称、y 值、误差线值):

cat1 15 0
cat1 18 3
cat2 13 0
cat2 10 4

它产生了下面的图,它朝着正确的方向发展,但还不理想(所有数据点都具有相同的颜色,对于单个值,您仍然可以看到使用了误差线;分组也不是'非常好——如果组成一对的两个点彼此更接近,那么情节就更容易看出来了)。

where I have got so far

如果有人有任何建议(即使是创建一个看起来与我一开始给出的示例不完全一样的图表)。我会很感激。

非常感谢您的宝贵时间!

最佳答案

在 Matplotlib 中,您可以单独设置刻度。 one of Matplotlib's examples 中解释了该方法.

这是一个开始:

# Initializations:
from matplotlib import pyplot as pp
import numpy as np

pp.ion()  # "Interactive mode on": pyplot.* commands draw immediately

# Data:
series_red_y = [1.3, 1.4, 2.2]
series_blue_y = [1.6, 1.8, 1.8]
series_blue_err = [0.25, 0.25, 0.5]
names = ('Category 1', 'Category 2', 'Category 3')

# Where on the x-axis the data will go:    
series_red_x = np.arange(0, 3*len(series_red_y), 3)  # Step of 3: red dot, blue dot, empty space
series_blue_x = np.arange(1, 3*len(series_blue_y)+1, 3)  # Step of 3: red dot, blue dot, empty space

# Plotting:
pp.scatter(series_red_x, series_red_y, c='r', s=100)
pp.scatter(series_blue_x, series_blue_y, s=100)
pp.errorbar(series_blue_x, series_blue_y, yerr=series_blue_err, fmt=None,
            capsize=0)
pp.xticks((series_red_x+series_blue_x)/2., names)

# We wait until the user is ready to close the program:
raw_input('Press enter...')

这是结果,您可以根据自己的特定需求对其进行自定义:

enter image description here

关于python - Gnuplot(或 matplotlib): create non-bar chart with categories on x-axis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8371993/

相关文章:

python-3.x - python中的磁偶极子

python - 绕过默认时区在Django中获取带时区的系统时间

python - 编写单独的 JSON 条目 Python 时遇到问题

大块/内存管理中的python read()和write()

Java有向图框架

python - key 错误 : 'type' while drawing a scatter plot with grouped x axis in Python

python - 使用 pytest,为什么单个测试结果与运行所有测试不同?

带接口(interface)的 C# 类型联合

python - 将 pandas 数据框转换为定向 networkx 多图

python - 子图背景渐变色