- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot int to datetime on X-axis using Seaborn?
To plot int to datetime on X-axis using Seaborn in matplotlib, we can take the following steps
Steps
Set the figure size and adjust the padding between and around the subplots.
Create a dataframe, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data, with three columns.
Create a countplot with int, i.e., dob on the X-axis.
Set int to datetime label on the X-axis.
To display the figure, use Show() method.
Example
import seaborn as sns from matplotlib import pyplot as plt import pandas as pd import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Data frame with 3 columns df = pd.DataFrame([ [23, 'James', 1259969793926], [39, 'Jimmy', 1259969793927], [56, 'Jack', 1259969793929], [60, 'Tom', 1259969793928], [80, 'Tim', 1259969793939] ], columns=['marks', 'names', 'dob']) # Create a Countplot with df ax = sns.countplot(x="dob", data=df) ax.set_xticklabels( [ pd.to_datetime(tm, unit='ms').strftime('%Y-%m-%d %H:%M:%S') for tm in ax.get_xticks() ], rotation=45) # Display the plot plt.show()
Output
It will produce the following output −
- Related Articles
- How to plot a rectangle on a datetime axis using Matplotlib?
- How to remove or hide X-axis labels from a Seaborn / Matplotlib plot?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to plot multi-color line if X-axis is datetime index of Pandas?
- How to plot data against specific dates on the X-axis using Matplotlib?
- How to plot two violin plot series on the same graph using Seaborn?
- How to add a legend on Seaborn facetgrid bar plot using Matplotlib?
- How to display raise to the power on X-axis in base R plot?
- How to plot the X-axis labels on the upper-side of the plot in R?
- How to plot values with log scales on x and y axis or on a single axis in R?
- How to create a plot in base R with dates sequence on X-axis?
- How to remove the axis tick marks on a Seaborn heatmap?
- How to plot multiple Seaborn Jointplot in Subplot using Matplotlib?
- How to X-axis labels to the top of the plot using ggplot2 in R?
- Add minor gridlines to Matplotlib plot using Seaborn

Advertisements