到目前为止我有这张图,它有点难看。每种类型的标记都是一种算法的准确度。
这有两个问题:
对于#1我尝试使用xticks,如下所示,但没有太大的成功。
对于#2,将数据抛入np.log10()
很简单,但轴刻度也会进行对数转换。我觉得应该有一个简单的方法来做这个日志显示(看起来很正常)?
到目前为止,这是我的代码:
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import random
# create fake data
data = {}
data['A'] = []
data['B'] = []
data['C'] = []
n = 5
data['A'] = zip(np.random.uniform(0, 10000, size=n), np.random.uniform(0, 0.6, size=n))
data['B'] = zip(np.random.uniform(0, 200, size=n), np.random.uniform(0, 0.6, size=n))
data['C'] = zip(np.random.uniform(0, 5000, size=n), np.random.uniform(0, 0.6, size=n))
# make graph
markers = ['+', '*', 'x']
colors = ['b', 'r', 'g']
fig = plt.figure()
ax1 = fig.add_subplot(111)
plots = []
labels = []
# extract data
i = 0
for algorithm in ['A', 'B', 'C']:
results = data[algorithm]
testing = np.array([float(x[1]) for x in results if x > 0.0])
ts = np.array([int(x[0]) for x in results if x > 0.0])
color = colors[i]
marker = markers[i]
plot = ax1.scatter(ts, testing, color=color, marker=marker, s=10)
plots.append(plot)
labels.append(algorithm)
i += 1
# set axis and title
ax1.legend(plots, labels, loc='lower right')
ax1.set_xlabel("Time (sec)")
ax1.set_ylabel("Testing Accuracy")
ax1.set_title("Time versus testing accuracy")
# set axis limits
xticks, xticklabels = plt.xticks()
xmin = (3*xticks[0] - xticks[1])/2.
xmax = (3*xticks[-1] - xticks[-2])/2.
plt.xlim(xmin, xmax)
plt.xticks(xticks)
plt.ylim(0.0, 1.0)
# save to disk
plt.savefig("scatter.eps")
答案 0 :(得分:1)
为什么你不这样做?
ax1.set_ylim( -.1, 1.1 )
ax1.set_yticks( np.linspace(0, 1, 10) )
ax1.set_xscale('log')