python - Set xticks interval with date values
问题描述
Hello I have a a list that has about 150 dates that are stored in string format. I would like to set an interval so that there are only 10 ticks along the x-axis I am not sure how to do this without changing the type format.
'1980-06',
'1980-09',
'1980-12',
'1981-03',
'1981-06',
'1981-09',
'1981-12',
...
解决方案
您可以提供要显示的刻度列表。要获得该刻度列表,只需将您的日期列表分成十部分,然后找出每个刻度应该有多远。然后使用 Python 的索引来获取刻度的值。检查以下:
import math
dates = ['1980-06', '1980-09', '1980-12', '1981-12' ...] # Your date list
date_len = len(dates)
step = int(math.ceil(date_len/10))
ticks = dates[::step] # ticks to show on graph
推荐阅读
- shell - `command > output` 和 `command 2>&1 > output` 有什么区别?
- android - How can I prevent closing app when I double-click fast in Android?
- android - How to set floating button visibility to GONE when floating button arrives to the same height position of a TextView inside NestedScrollView?
- spring - 带有 multipart/form-data 的请求返回 415 错误
- javascript - 响应式地在页面上将卡片网格居中并左对齐卡片
- python - Python - Image to text enclosed in pentagon shape pytesseract
- angular - Angular 8 TypeError: Cannot add property 2, object is not extensible
- python - APIErrorException: (BadArgument) 'recognitionModel' is incompatible :AZURE COGNITIVE FACE
- django-forms - How to set each field as required for formset_factory in Django (how to validate blank forms in formsets)
- windows - 从PowerShell中的多个测试文件中提取多列