0

Fellow coders. I am fairly new to Matplotlib.

I would like to plot the 4 headings in one graph. All 4 heading observations are timestamped and the # = 3600. See image below:

.

As of yet I only manage to plot one graph and this takes about one minute to load.

The x-axis is log time in seconds, what I would like to display is a change in the annotation to ten minutes or 600 sec so that the displayed time is not a black block. The y-axis is heading in degrees.

# data entry
x = df["time"]

pg1 = df["Seapath_Heading"]
#sg1 = df["Protrack"]
#sg2 = df["NMEAGyro3"]
#sg3 = df["HiPAPGyro400NMEA"]

plt.plot(x, pg1)
#plt.plot(x, sg1)
#plt.plot(x, sg2)
#plt.plot(x, sg3)

plt.xlabel("logtime(sec)")
plt.ylabel("Heading(ddd.dd)")
plt.title("Gyro linechart overview")

plt.show()
Eliahu Aaron
  • 4,103
  • 5
  • 27
  • 37
mR.bLuEsKy
  • 13
  • 1
  • 3
  • What type is `df['time']`? I suspect it's `object` meaning strings. This should "just work" if it would be a timestamp or number. Try `pd.to_datetime` – MaxNoe Dec 10 '19 at 12:08
  • `print(df.dtypes)` – MaxNoe Dec 10 '19 at 12:08
  • You need to convert your strings to dates first. Then you can use locators to set the interval. Check the answer to the [duplicate](https://stackoverflow.com/questions/44213781/pandas-dataframe-line-plot-display-date-on-xaxis/44214830#44214830) (using `df['date'] = pd.to_datetime(df['date'])`) and also [xticks-every-15-minutes-starting-on-the-hour](https://stackoverflow.com/questions/42398264/matplotlib-xticks-every-15-minutes-starting-on-the-hour) – ImportanceOfBeingErnest Dec 10 '19 at 12:09

1 Answers1

-1

You can create your own array of how you'd like your x axes to be, and use pyplot.xticks:

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

# Making up a plot that looks too crowded
a = np.arange(0, 3600, 100)
plt.plot(a, a)
plt.xticks(a)
plt.xlabel("Time [s]")
plt.show()

Result:

enter image description here

# Creating xticks, show every 600 secs only
dt = 600
ticks = np.arange(0, 3600 + dt, dt)
plt.plot(a, a)
plt.xticks(ticks)
plt.xlabel("Time [s]")
plt.show()

enter image description here

Check the pyplot.xticks Documentation