这确实是一个品味问题,也是一个目标受众的问题。matplotlib
试图为科学目的提供清晰的插图。这必然是一种妥协,并且插图不是您会在杂志上打印或在广告中展示的东西。
有一些好消息和一些坏消息matplotlib
在这个意义上。
坏消息:
- 没有任何一个神奇的命令或包可以创建美丽的情节
matplotlib
.
好消息:
- 有一些简单的方法可以更改默认设置,请参阅:http://matplotlib.org/users/customizing.html http://matplotlib.org/users/customizing.html
- 对象模型使用户能够更改几乎所有内容并引入复杂的新功能。
- 源代码是可用的,甚至用户可以很容易地更改它。
在我看来,最困难的事情是决定你想要什么。然后做你想做的事会更容易,即使一开始有一个陡峭的学习曲线。
举个例子:
import numpy as np
import matplotlib.pyplot as plt
# create some fictive access data by hour
xdata = np.arange(25)
ydata = np.random.randint(10, 20, 25)
ydata[24] = ydata[0]
# let us make a simple graph
fig = plt.figure(figsize=[7,5])
ax = plt.subplot(111)
l = ax.fill_between(xdata, ydata)
# set the basic properties
ax.set_xlabel('Time of posting (US EST)')
ax.set_ylabel('Percentage of Frontpaged Submissions')
ax.set_title('Likelihood of Reaching the Frontpage')
# set the limits
ax.set_xlim(0, 24)
ax.set_ylim(6, 24)
# set the grid on
ax.grid('on')
(只是评论:原始图像中的 X 轴限制没有考虑数据的周期性。)
这会给我们这样的东西:
很容易理解,我们需要做很多改变才能向缺乏工程意识的观众展示这一点。至少:
- 使填充透明且颜色不那么刺眼
- 让线条变粗
- 改变线条颜色
- 向 X 轴添加更多刻度
- 更改标题的字体
# change the fill into a blueish color with opacity .3
l.set_facecolors([[.5,.5,.8,.3]])
# change the edge color (bluish and transparentish) and thickness
l.set_edgecolors([[0, 0, .5, .3]])
l.set_linewidths([3])
# add more ticks
ax.set_xticks(np.arange(25))
# remove tick marks
ax.xaxis.set_tick_params(size=0)
ax.yaxis.set_tick_params(size=0)
# change the color of the top and right spines to opaque gray
ax.spines['right'].set_color((.8,.8,.8))
ax.spines['top'].set_color((.8,.8,.8))
# tweak the axis labels
xlab = ax.xaxis.get_label()
ylab = ax.yaxis.get_label()
xlab.set_style('italic')
xlab.set_size(10)
ylab.set_style('italic')
ylab.set_size(10)
# tweak the title
ttl = ax.title
ttl.set_weight('bold')
现在我们有:
这与问题中的情况并不完全一样,但一切都可以朝着这个方向调整。此处设置的许多内容都可以设置为默认值matplotlib
。也许这给出了如何改变情节中的事情的想法。