
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Pandas timeseries plot setting X-axis major and minor ticks and labels
Using Pandas, we can create a dataframe with time and speed, and thereafter, we can use the data frame to get the desired plot.
Steps
Construct a new Generator with the default BitGenerator (PCG64).
Using Pandas, get a fixed frequency DatetimeIndex. From '2020-01-01' to '2021-01-01'.
Draw samples from a log-normal distribution.
Make a data frame with above data.
Using panda dataframe create plot, with figsize = (10, 5).
To show the figure, use the plt.show() method.
Example
import numpy as np import pandas as pd from matplotlib import pyplot as plt rng = np.random.default_rng(seed=1) date_day = pd.date_range(start='2020-01-01', end='2021-01-01', freq='D') traffic = rng.lognormal(sigma=2, size=date_day.size) df_day = pd.DataFrame(dict(speed=[pow(2, -i) for i in range(len(date_day))]), index=date_day) df_day.plot(figsize=(10, 5)) plt.show()
Output
- Related Articles
- How to rotate X-axis tick labels in Pandas bar plot?
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- Hiding major tick labels while showing minor tick labels in Matplotlib
- How to independently set horizontal and vertical, major and minor gridlines of a plot?
- How to create minor ticks for a polar plot in matplotlib?
- How to display axes ticks and labels inside the plot using ggplot2 in R?
- How to turn on minor ticks only on the y-axis Matplotlib?
- How to disable the minor ticks of a log-plot in Matplotlib?
- How to display X-axis labels inside the plot in base R?
- How to display X-axis labels with dash in base R plot?
- Setting Y-axis in Matplotlib using Pandas
- How to plot the X-axis labels on the upper-side of the plot in R?
- How to remove or hide X-axis labels from a Seaborn / Matplotlib plot?
- How to set Dataframe Column value as X-axis labels in Python Pandas?
- How to customize X-axis ticks in Matplotlib?

Advertisements