Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matplotlib中多个图表的自定义x轴_Matplotlib - Fatal编程技术网

Matplotlib中多个图表的自定义x轴

Matplotlib中多个图表的自定义x轴,matplotlib,Matplotlib,我需要标记图形的最小值和最大值。我的代码只在所有图形中的一个上标记它们 import matplotlib.pyplot as my_graph import matplotlib.dates as mdates def several_tag(tags): mmin=[] mmax=[] current_db=r.hget('db_id', 'value') data=db_arch[current_db] for counter, ctag in e

我需要标记图形的最小值和最大值。我的代码只在所有图形中的一个上标记它们

import matplotlib.pyplot as my_graph
import matplotlib.dates as mdates
def several_tag(tags):
    mmin=[]
    mmax=[]
    current_db=r.hget('db_id', 'value')
    data=db_arch[current_db]

    for counter, ctag in enumerate(tags):
        vals=[]
        times=[]
        tag_values=data.find({'tagname':ctag},{'value':1,'time':1,'_id':0})
        for tag in tag_values:
            try:
                vals.append(round(float(tag['value']),2))
            except:
                vals.append(0)
            times.append(datetime.fromtimestamp(tag['time']))

        mmin.append(min(vals))
        mmax.append(max(vals))
        my_graph.ylim(min(mmin)-5,max(mmax)+5)

        my_graph.plot(times, vals)


        def paint_x(vals):
            my_graph.gca().xaxis.set_major_formatter(mdates.DateFormatter("%H:%M:%S"))
            locator=mdates.ticker.FixedLocator([mdates.date2num(times[vals.index(min(vals))]),mdates.date2num(times[vals.index(max(vals))])])
            my_graph.gca().xaxis.set_major_locator(locator)

        paint_x(vals)

        my_graph.xticks(size="xx-small", color="gray")

        my_graph.annotate('max: %s' % max(vals), size="x-small", color="red", xy=(mdates.date2num(times[vals.index(max(vals))]), max(vals)), xycoords='data', xytext=(10, 10), textcoords='offset points', arrowprops=dict(arrowstyle='-|>'))
        my_graph.annotate('min: %s' % min(vals), size="x-small", color=(0.4, 0.5, 0.3), xy=(mdates.date2num(times[vals.index(min(vals))]), min(vals)), xycoords='data', xytext=(15, -15), textcoords='offset points', arrowprops=dict(arrowstyle='-|>'))

        my_graph.grid(True)

    my_graph.savefig(r'1.png', transparent=True)


several_tag(['MKA50GE004ZQ_V', 'MKA50GE003ZQ_V'])
结果:


如何获得极值的标记​​在所有图表的时间轴上?

从包含的图像中可以看出,所有绘图都具有所需的最小值/最大值。到底是什么问题?@GregHow想要得到一个极值的标记​​在所有图表的时间线上?你所说的图表是什么意思,你所显示的图表已经标记了最小值和最大值,你还想要什么?请提供更多细节,否则人们无法理解您的要求。