2017-04-20 1 views
0

간단한 질문이 있습니다. 나는 일주일/한 달 동안의 생계를 시뮬레이트하는 프로그램을 가지고있다. 당분간은 실패 할 수 있기 때문에 현금 인출기 (나는 내 ​​언어에서 올바르게 번역했는지 모르겠다)를 처리하며, 일부 전문가는 상점에 와서 수리해야한다.Matplotlib xticks as days

enter image description here

cashdesk 몇 가지 오류를 얻었다 때 1.0 상태가 발생이/파산, 다음 그것을 수리 기술자 기다린 다음 : 시뮬레이션의 끝에서, 프로그램은 다음과 같이 그래프을 나타내는 그것은 작동 상태 인 0으로 돌아갑니다.

나 또는 내 프로젝트 담당자가 축보다 x 축이 아닌 다른 것을 보게 될 것입니다. 내가 어떻게 해? 나는 그것을 등 다음 간격, Day 2,

내가 아는 약 pyplot.xticks() 방법, Day 1처럼하고 싶은 말은하지만, 그럼, 첫 번째 인수의 목록에있는 진드기에 레이블을 할당 나는 분과 함께 2000 개의 레이블을 만들어야 할 것입니다. 그리고 7 일만 쓰고 싶습니다.

+0

하루에 1,440 분이 있습니다. 줄거리가 하루 이상 반만 보이지 않습니까? – dpwilson

답변

1

thisthis 개의 질문에 영감을 받아 matplotlib set_ticks 및 get_xticklabels() 메소드를 사용할 수 있습니다.

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 

minutes_in_day = 24 * 60 

test = pd.Series(np.random.binomial(1, 0.002, 7 * minutes_in_day)) 

fig, ax = plt.subplots(1) 
test.plot(ax = ax) 

start, end = ax.get_xlim() 
ax.xaxis.set_ticks(np.arange(start, end, minutes_in_day)) 

labels = ['Day\n %d'%(int(item.get_text())/minutes_in_day+ 1) for item in ax.get_xticklabels()] 
ax.set_xticklabels(labels) 

아래 그림과 같습니다.

enter image description here

+2

하루에 60 분 밖에 없습니까? – ImportanceOfBeingErnest

+0

그 점을 알려 주셔서 감사합니다. 결정된 – FLab

1

당신은 plt.xticks()과 올바른 궤도에있어. 이것을 시도하십시오 :

import matplotlib.pyplot as plt 

# Generate dummy data 
x_minutes = range(1, 2001) 
y = [i*2 for i in x_minutes] 

# Convert minutes to days 
x_days = [i/1440.0 for i in x_minutes] 

# Plot the data over the newly created days list 
plt.plot(x_days, y) 

# Create labels using some string formatting 
labels = ['Day %d' % (item) for item in range(int(min(x_days)), int(max(x_days)+1))] 

# Set the tick strings 
plt.xticks(range(len(labels)), labels) 

# Show the plot 
plt.show() 
관련 문제