0

I have attempted to plot a line on my dataset at hr=2, however it changes my x axis scale by about 35 years for some reason. The dataset has 420 datapoints across 6 hours, hence the number in the middle two lines.

fig= plt.figure(figsize=(9,2.7))
iplt.plot(pressure_no1, color='black')

plt.plot(np.linspace(-2, 4, 20), pressure_no1.data)
plt.axvline(0)

plt.xlabel('Time / hour of day')
plt.ylabel('Atmospheric pressure / kPa')
iplt.show()

This code gives me this graph: skewed scale graph the far left blue line is the inserted function line, and far right is the actual data

And this is how the scale should actually be: original graph

Please help, i have no idea how to fix this. Thanks in advance :)

Derek O
  • 16,770
  • 4
  • 24
  • 43
  • Check your datetimes. One of them is probably misformatted and being interpreted as 1970-01-01. Can you give a sample of the `pressure_no1` DataFrame? – Derek O Apr 01 '21 at 17:06
  • @DerekO, the package used here looks to be iris, not pandas. So the [python-iris] tag was correct. https://scitools-iris.readthedocs.io/en/stable/index.html – RuthC Apr 07 '21 at 15:47
  • @RuthC oh thank you for correcting me — that was my mistake and I'll add the tag back so people can find this question and your answer. Cheers! – Derek O Apr 07 '21 at 16:58
  • @RuthC Hi Ruth, I don't mean to be cheeky but i would really appreciate it if you had a look at my latest post about cube averaging. I am very new to this and my dissertation in due in a few weeks, and my disseration advisor isn't replying with a solution. I only asked as your solved my other two issues perfectly! :) https://stackoverflow.com/questions/67004292/how-to-average-multiple-iris-cubes-of-each-time-coordinate?noredirect=1#comment118437783_67004292. – Antonia Lily Apr 08 '21 at 13:18

1 Answers1

0

Since you are plotting your cube against time, you probably need to specify your vertical line with a datetime:

import datetime

import iris
import iris.quickplot as qplt
import numpy as np
import matplotlib.pyplot as plt

measures = np.random.normal(size=(360, ))
timepoints = np.arange(start=0, stop=360)

cube = iris.cube.Cube(measures, long_name='atmospheric_pressure', units='kPa')
time_coord = iris.coords.DimCoord(
    timepoints, units='minutes since 2020-07-01 00:00', standard_name='time')
cube.add_dim_coord(time_coord, 0)

qplt.plot(cube, color='k')
plt.axvline(datetime.datetime(2020, 7, 1, 2, 0), color='b')

plt.show()

enter image description here

RuthC
  • 1,269
  • 1
  • 10
  • 21