使用pyplot绘制对数图

Shuai Zhang

我正在使用pyplot绘制对数图。这是代码:

data = [...] # a list of int values
from scipy.stats import itemfreq
tmp = itemfreq(data) # Get the item frequencies
x = tmp[:, 0] # unique values in data
y = tmp[:, 1] # freq

import matplotlib.pyplot as plt
plt.loglog(x, y, basex=2, basey=2)
plt.show()

我得到这张图片: 对数图

但是我不希望数据点通过线连接起来,这看起来很难看。我怎样才能做到这一点?

物理学家

你可以给plt.loglog()函数几种不同的关键字参数,这将改变你的情节的格式,如linestylemarker和它们各自的颜色。

data = [...] # a list of int values
from scipy.stats import itemfreq
tmp = itemfreq(data) # Get the item frequencies
x = tmp[:, 0] # unique values in data
y = tmp[:, 1] # freq

import matplotlib.pyplot as plt
plt.loglog(x, y, basex=2, basey=2, linestyle='None', 
           marker='x', markeredgecolor='red')
plt.show()

或者,您可以提供一个字符串作为第三个位置参数,该字符串可以以一种更简单的方式选择格式,例如plt.loglog(x, y, 'rx'),将提供与上述相同的格式(没有带红叉的行)。可用的格式字符串参数可在此处找到

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章