-1

I have two numpy arrays: time and year. The time column contains timestamps for one day and contains 1440 rows, in which each row represents a ten minute interval. For example, time = [10, 20, 30, ..., 1440]. You can think of the time column as a 'Count' column. The year column contains years from 1996 to 2020, which looks like the following: year = [1996, 1996, ..., 1997, 1997, 1997, ..., 2020, 2020, 2020, 2020]. I have posted the code and the plot below what I have been able to generate so far. I would like to limit the y-axis to (144 x 366 x 25 = 1317600). Any help would be greatly appreciated.

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import scipy.io
import pandas as pd
import numpy as np
import seaborn as sns

mat = scipy.io.loadmat(r'C:\LocalData\sujaiban\sujai.banerji\fieldcourse_hyytiala\Data\Hyytiala\DMPS GR & J\J_325_19962020_10min.mat')

dN_dt_df = pd.DataFrame()

dN_dt_df = mat

J325 = list(dN_dt_df.values())[3]  

J325_df = pd.DataFrame(J325, columns = ['Time in datenum', 'Formation rate 3-25 nm', 'dN/dt', 'Coagulation sink term', 'Growth rate term', 'Particle number concentrations'])
matlab_datenum = J325_df['Time in datenum'].astype(int)

matlab_datenum_numpy_array = matlab_datenum.to_numpy()

python_datetime_pandas_dataframe = pd.to_datetime(matlab_datenum_numpy_array - 719529, unit = 'D')

df = pd.DataFrame(python_datetime_pandas_dataframe, columns = ['DateTime'])
df['Date'] = df['DateTime'].dt.strftime('%d/%m/%Y')
df['Time'] = df['DateTime'].dt.strftime('%H:%M')
df['Year'] = df['DateTime'].dt.year
python_year_pandas_dataframe = df['Year']

year = python_year_pandas_dataframe.to_numpy()

series_of_date_strings = pd.Series(df['Year'], dtype = 'string')

series_of_ten_minutes = np.zeros(shape = (144, 1), dtype = 'int')
i = 0
for j in range(10, 1450, 10):
    series_of_ten_minutes[i] = j
    i = i + 1

time = series_of_ten_minutes

sns.set_style('white')
sns.histplot(x = year)
plt.ylim(0, 1317600)

enter image description here

Ajgar Dev
  • 35
  • 8

1 Answers1

1

Adding

sns.set_style('white')
sns.histplot(x = year)
plt.ylim(0, 1440)

should do the trick as documented in this thread.

However, this cuts all bars rendering the barchart meaningless.

7shoe
  • 1,438
  • 1
  • 8
  • 12
  • Sorry, it upper limit of the y-axis should be (144 x 366 x 25 = 1317600). But then, what I am getting as shown in the edited question above is also not ideal. – Ajgar Dev Aug 02 '22 at 18:26
  • 1
    Eyeballing the plot above, I'd start with `plt.ylim(30000,55000)` and then finetune iteratively until it looks good. – 7shoe Aug 02 '22 at 18:27
  • 1
    `plt.ylim(30000,55000)` is not an acceptable way to show bar plots. They should always start at 0. The better option is to set the y-scale to log. – Trenton McKinney Aug 02 '22 at 18:58