我使用matplotlib(Python)中的boxplot来创建框图,我创建了许多具有不同日期的图形。在x轴上,数据是离散的。在
x轴上以秒为单位的值为0.25、0.5、1、2、5。。。。28800这些值是任意选择的(它们是采样周期)。在某些图上,由于数据不可用,因此缺少一个或两个值。在这些图上,x轴调整自身大小以分散其他值。在
我希望所有的图形在x轴上的同一个位置上都有相同的值(如果x轴显示一个值并不重要,但图形上没有绘制数据)
有人能告诉我有没有办法指定x轴的值?或者用另一种方法在同一个地方保持相同的值。在
规范相关章节如下:
对我来说,加入myDataframe.groupby(“日期”):
graphFilename = (basename+'_' + str(i) + '.png')
plt.figure(graphFilename)
group.boxplot(by=["SamplePeriod_seconds"], sym='g+') ## colour = 'blue'
plt.grid(True)
axes = plt.gca()
axes.set_ylim([0,30000])
plt.ylabel('Average distance (m)', fontsize =8)
plt.xlabel('GPS sample interval (s)', fontsize=8)
plt.tick_params(axis='x', which='major', labelsize=8)
plt.tick_params(axis='y', which='major', labelsize=8)
plt.xticks(rotation=90)
plt.title(str(i) + ' - ' + 'Average distance travelled by cattle over 24 hour period', fontsize=9)
plt.suptitle('')
plt.savefig(graphFilename)
plt.close()
如果有人帮忙,我会继续在谷歌上搜索。谢谢:)
非常感谢大家的帮助,用你们的回答我得到了下面的代码。(我意识到它可能会改进,但很高兴它起作用了,我现在可以查看数据:)
{cd1>在默认情况下,{cd1>只绘制连续轴上的位置。遗漏的数据被忽略了,仅仅是因为箱线图不知道它们丢失了。但是,可以使用
positions
参数手动设置框的位置。 下面的示例执行此操作,因此即使缺少值,也会生成相等范围的绘图。在如果
SamplePeriod_seconds
列中的值不是等间距的,这仍然有效,但是如果它们相差很大,这将不会产生好的结果,因为这些条会重叠:然而,这并不是绘图本身的问题。为了得到进一步的帮助,我们需要知道你期望图的结尾是什么样子。在
如果你尝试这样做:
其中x是x值的数组,5是沿轴的步数。在
这同样适用于带有yticks的y轴。希望有帮助!:)
编辑:
我已经删除了我没有的实例,但是下面的代码应该给你一个网格来绘制:
^{pr2}$尝试在此基础上插入您的值:)
相关问题 更多 >
编程相关推荐