2

I have a data set that consists of 1440 rows × 297 columns. I tried to plot 03_jan_2018 in terms of Time(X-Axis) and Density (Y-Axis), but I'm faced with a problem. The outcome graph is not enough clear and also the X-Axis is not appeared!!

I would like to make something like this:

enter image description here

But I'm ending up with this:

enter image description here

Can anyone help me?

Thanks in advance!

vestland
  • 55,229
  • 37
  • 187
  • 305
Alisha
  • 61
  • 1
  • 6

3 Answers3

0

An easy fix for this is to increase the figure size.

plt.figure(figsize=(80,40))
plt.plot(data.hour_formatted, data['03_jan_18'])
plt.show()
Stefan Mesken
  • 1,283
  • 2
  • 9
  • 9
0

I would use the plt.xticks(np.arange(0,25,6)) to select just the hours that you want. It looks like it's trying to put in too many of them by default, and really you want just a handful of values (in this case only every 6 hours has a tick). Tune the range value to just give the ones you want.

NGeorgescu
  • 27
  • 2
0

The x-axis has appeared, but it seems that you're facing the same problem as described here. Anyway, I'll show you how you can get what you want and also avoid possible problems with the x-axis notations.

Plot 1:

enter image description here

Code 1:

# imports
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# random data or other data sources
np.random.seed(123)
rows = 1440
df = pd.DataFrame(np.random.uniform(-1,1,size=(rows, 2)),
                  index=pd.date_range('1/1/2000', periods=1440),
                    columns=list('AB'))

df['A'] = df['A'].cumsum()
df['B'] = df['B'].cumsum()

# Plot
fig, ax = plt.subplots()
t = df.index
ax.plot(t, df['A'])
ax.plot(t, df['B'], color='red')

You can also edit and adjust the axis notations like this:

Plot 2:

enter image description here

Code 2:

# imports
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# random data or other data sources
np.random.seed(123)
rows = 1440
df = pd.DataFrame(np.random.uniform(-1,1,size=(rows, 2)),
                  index=pd.date_range('1/1/2020', periods=1440),
                    columns=list('AB'))

df['A'] = df['A'].cumsum()
df['B'] = df['B'].cumsum()

# Make a list of empty myLabels
myLabels = ['']*len(df.index)

# Plot
fig, ax = plt.subplots()
t = df.index
ax.plot(t, df['A'])
ax.plot(t, df['B'], color='red')

# Set labels on every Nth element in myLabels specified by the interval variable
myLabels = ['']*len(df.index)
interval = 2
myLabels[::interval] = [item.strftime('%Y - %m - %d') for item in df.index[::interval]]
ax.xaxis.set_major_formatter(ticker.FixedFormatter(myLabels))
plt.gcf().autofmt_xdate()

# Tilt the labels
plt.setp(ax.get_xticklabels(), rotation=30, fontsize=10)
plt.show()
vestland
  • 55,229
  • 37
  • 187
  • 305