Xtick spacing for matplotlib

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Xtick spacing for matplotlib



I am trying to plot the graph with X axis plotting time and Y axis plotting memory used. I parse this data from log file which has about 5 days of data and I want to plot all the numbers as is. I am pretty new to matplotlib, so not able to figure out how to add space for xticks. I am able to generate the graph for 24 hour period, but xticks are very much cluttered.



Graph for 24 hours data



Here's the code:


import datetime
import random
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
import numpy as np



x = ['11:26', '11:36', '11:43', '11:50', '11:58', '12:05', '12:13', '12:20', '12:27', '12:33', '12:38', '12:44', '12:49', '12:54', '12:59', '13:04', '13:10', '13:15', '13:21', '13:27', '13:33', '13:39', '13:46', '13:53', '14:00', '14:07', '14:15', '14:20', '14:35', '14:50', '15:05', '15:20', '15:35', '16:06', '16:15', '16:23', '16:30', '16:37', '16:45', '16:52', '16:59', '17:07', '17:13', '17:18', '17:23', '17:28', '17:34', '17:39', '17:44', '17:49', '17:55', '18:01', '18:07', '18:13', '18:19', '18:26', '18:33', '18:40', '18:47', '18:54', '18:59', '19:15', '19:30', '19:45', '20:00', '20:15', '20:46', '20:55', '21:03', '21:10', '21:17', '21:25', '21:32', '21:40', '21:47', '21:53', '21:58', '22:03', '22:09', '22:14', '22:19', '22:24', '22:29', '22:35', '22:41', '22:47', '22:53', '22:59', '23:06', '23:13', '23:20', '23:27', '23:34', '23:39', '23:55', '00:10', '00:25', '00:40', '00:55', '01:26', '01:35', '01:43', '01:50', '01:57', '02:05', '02:12', '02:19', '02:26', '02:33', '02:38', '02:43', '02:48', '02:53', '02:59', '03:04', '03:09', '03:15', '03:21', '03:27', '03:33', '03:39', '03:46', '03:53', '04:00', '04:07', '04:14', '04:19', '04:34', '04:49', '05:05', '05:20', '05:35', '06:05', '06:15', '06:22', '06:29', '06:37', '06:44', '06:52', '06:59', '07:06', '07:12', '07:17', '07:23', '07:28', '07:33', '07:38', '07:43', '07:49', '07:55', '08:01', '08:06', '08:12', '08:18', '08:25', '08:32', '08:40', '08:47', '08:54', '08:59', '09:14', '09:29', '09:44', '09:59', '10:14', '10:45', '10:54', '11:02', '11:09', '11:16', '11:24']
y = [8119756, 7862656, 7930220, 7964840, 7969156, 7971444, 7973372, 7987932, 7987336, 7893752, 7941384, 8010040, 7974324, 7904344, 7994804, 8022468, 8027888, 8034508, 8009516, 8005600, 8008008, 8009392, 8042148, 8016556, 8052232, 8028808, 8058596, 7510520, 7511548, 7526412, 7568928, 7602368, 7602368, 8284188, 8389260, 8395832, 8449324, 8472664, 8522396, 8527608, 8533316, 8499792, 8315568, 8364208, 8498216, 8487636, 8334352, 8441284, 8553968, 8526356, 8529896, 8522300, 8512912, 8537832, 8509352, 8517080, 8515768, 8560672, 8555192, 8522156, 8034560, 8061808, 8055152, 8061916, 8116656, 8116656, 8316820, 8306224, 8359536, 8424432, 8471660, 8494028, 8548792, 8512484, 8540924, 8310224, 8422936, 8495848, 8491500, 8294264, 8407840, 8512332, 8502440, 8510632, 8521212, 8525880, 8505476, 8530504, 8501076, 8549408, 8514888, 8521116, 8511076, 8013324, 8060580, 8017212, 8088956, 8082892, 8082892, 8360536, 8341988, 8441768, 8466644, 8459788, 8511404, 8522024, 8520540, 8509496, 8312028, 8374172, 8504160, 8487816, 8281568, 8405264, 8470692, 8471572, 8473404, 8438832, 8435352, 8449072, 8441444, 8476268, 8446284, 8487840, 8450572, 8495488, 7998268, 7937864, 7963976, 7953340, 8023880, 8023880, 8402204, 8355472, 8435288, 8459012, 8468036, 8514588, 8526636, 8505516, 8511264, 8291852, 8385664, 8484208, 8468764, 8353152, 8410588, 8525012, 8515584, 8518596, 8522508, 8505692, 8527032, 8505688, 8508916, 8510200, 8517840, 8545512, 8525096, 8024876, 8040276, 8042692, 8073932, 8160228, 8160228, 8340560, 8351532, 8365188, 8494460, 8524280, 8538544]

# plot

plt.figure(figsize=(20,10),dpi=400)
plt.grid()

plt.gcf().canvas.draw()
plt.xticks(rotation='vertical', fontsize = 10, color='red')


ax = plt.gca()
ax.tick_params(axis='both', which='major', pad=10)



plt.plot(x, y, c = 'k', label = "Data")
plt.xlabel("Time of Testcase")
plt.ylabel("Memory Used")
plt.title("Longevity Data Analysis")
plt.legend()

plt.savefig("test1.png")
plt.show()









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS