title: Unexpected time axis min/max openpyxl
body: <p>I am trying to plot a few charts with the openpyxl library, here is my code so far:</p>
  <pre><code># openpyxl
  from openpyxl import Workbook, load_workbook
  from openpyxl.utils import get_column_letter
  from openpyxl.utils.dataframe import dataframe_to_rows
  from openpyxl.chart import *
  from openpyxl.chart.text import RichText
  from openpyxl.drawing import *
  from openpyxl.drawing.text import  RichTextProperties,Paragraph,ParagraphProperties, CharacterProperties
  from openpyxl.styles import NamedStyle
  from copy import deepcopy
  
  # other
  import pandas as pd
  import matplotlib.pyplot as plt
  import seaborn as sns
  # define input and output files
  file_input = r&quot;C:\LocalData\VirtualEnvironment_terraphase\Project_PointMolate\Test_Data1.xlsx&quot;
  file_output = r&quot;C:\LocalData\VirtualEnvironment_terraphase\Project_PointMolate\Test_Result1.xlsx&quot;
  
  # create workbook
  wb = Workbook()
  # create main data frame
  df_main = pd.read_excel(file_input)
  # determine number of columns in dataframe, this will be used later
  df_main_range_columns = len(df_main.columns) + 1
  # sort data frame
  df_main = df_main.sort_values(by=['LocCode','ChemName','SampleDate'])
  d={}
  
  for index, LocCode in enumerate(df_main['LocCode'].unique()):
      d[LocCode] = df_main[df_main['LocCode'] == LocCode]
      
      df_local_range_rows = len(d[LocCode]) + 2
      
      # create charts
      chart_scatter_analytical = ScatterChart(auto_axis=False)
      chart_scatter_gwe = ScatterChart(auto_axis=False)
      
      # create sheets, one sheet per LocCode
      #    create data sheet
      dataSheetName = LocCode + '_data'
      wb.create_sheet(dataSheetName)
      ws = wb[dataSheetName]
      #    create chart sheet
      chartSheetName = LocCode + '_chart'
      wb.create_chartsheet(chartSheetName)
      cs = wb[chartSheetName]
      
      # add each dataframe to sheet
      for dataframes in dataframe_to_rows(d[LocCode], index=True, header=True):
          ws.append(dataframes)
          
  #     # format dates
  #     date_style_customX = NamedStyle(name='date_style_customX', number_format='m/d/yyyy h:mm')
      
  #     for row in ws[2:ws.max_row]:
  #         cell = row[2]
  #         cell.style = date_style_customX
      
      # main loop, start by looping through analytes
      for index, Analyte in enumerate(d[LocCode]['ChemName'].unique()):
          # get column indices
          #    loop through each column headers, see if column header matches columns of interest (e.g. date, concentration, analyte, etc.) 
          for column in ws.iter_cols(min_row=1, max_row=1, min_col=1, max_col=df_main_range_columns):
              for cell in column:
                  if cell.value == 'SampleDate':
                      col_date = cell.column
                  elif cell.value == 'Concentration':
                      col_conc = cell.column
                  elif cell.value == 'ChemName':
                      col_analyte = cell.column
                      
          # get row indices for analyte
          #    create empty list to add row indices to
          row_analyte_list = []
          #    loop through each row (for each analyte) and add row indices to row list
          for row in ws.iter_rows(min_row=3, max_row=df_local_range_rows, min_col=col_analyte, max_col=col_analyte):            
              for cell in row:
                  if cell.value == Analyte:
                      row_analyte_list.append(cell.row)
          
          row_min = min(row_analyte_list)
          row_max = max(row_analyte_list)      
          
          data_x = Reference(ws, 
                             min_col=col_date, 
                             max_col=col_date, 
                             min_row=row_min, 
                             max_row=row_max)
          
          data_y = Reference(ws, 
                             min_col=col_conc, 
                             max_col=col_conc,
                             min_row=row_min, 
                             max_row=row_max)
  
          # create series
          series_analyte = Series(values = data_y, xvalues=data_x, title=Analyte)
          
          # style series
          series_analyte.marker.symbol = 'auto'
          # series_analyte.marker.graphicalProperties.solidFill = 'ffffff'
          
          # add series to charts
          # add analytical results to one chart, GWE to another
          if Analyte == 'GWE':
              chart_scatter_gwe.series.append(series_analyte)
          else:
              chart_scatter_analytical.series.append(series_analyte)
      
      # define no line style for gridlines
      sgp = shapes.GraphicalProperties(ln=line.LineProperties(noFill=True))
      
      # style charts
      # style gwe chart, this serves as the 'main' chart, since the analytical will be added to it
      chart_scatter_gwe.title = LocCode
      #    configure y-axis
      chart_scatter_gwe.y_axis.title = 'Elevation (ft)'
      chart_scatter_gwe.y_axis.majorGridlines.spPr = sgp
      chart_scatter_gwe.y_axis.majorTickMark = 'out'
      #    configure x-axis
      chart_scatter_gwe.x_axis.title = 'Date'
      chart_scatter_gwe.x_axis.number_format = 'd-mmm-yyyy'
      chart_scatter_gwe.x_axis.txPr = deepcopy(chart_scatter_gwe.x_axis.title.text.rich)
      chart_scatter_gwe.x_axis.txPr.properties.rot = &quot;-2700000&quot; # this value is in 60,000ths of a degree, so 45 degrees = 2,700,000, 60,000th degrees (see the comments in this post: https://stackoverflow.com/questions/40146418/rotate-the-axis-of-an-excel-chart-using-openpyxl)
      chart_scatter_gwe.x_axis.majorTickMark = 'out'
      # chart_scatter_gwe.x_axis.majorUnit = 31
      #     these two lines set the min/max of the x-axis, these are included here for testing purposes but will need to be changed in any actual project work
      # chart_scatter_gwe.x_axis.scaling.min = 44562.0
      # chart_scatter_gwe.x_axis.scaling.max = 44655.0
      
      # style analytical chart
      chart_scatter_analytical.y_axis.title = 'Concentration'
      chart_scatter_analytical.y_axis.majorTickMark = 'out'
      
      # configure axes
      chart_scatter_analytical.y_axis.axId = 200
      chart_scatter_gwe.y_axis.crosses = &quot;max&quot;
      
      # combine charts
      chart_scatter_gwe += chart_scatter_analytical
          
      # add chart to sheet
      cs.add_chart(chart_scatter_gwe)
     
      
  wb.save(file_output)
  </code></pre>
  <p>Here is my test input data: <a href="https://docs.google.com/spreadsheets/d/1qYtdmipPPwvlqupUY8Hgvz6saVXUM7WL/edit?usp=sharing&amp;ouid=104041081140482661384&amp;rtpof=true&amp;sd=true" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1qYtdmipPPwvlqupUY8Hgvz6saVXUM7WL/edit?usp=sharing&amp;ouid=104041081140482661384&amp;rtpof=true&amp;sd=true</a></p>
  <p>I'm expecting the code to produce 3 charts, one for each monitoring well (mw) in the LocCode column, that should look like this:</p>
  <p><a href="https://i.stack.imgur.com/uJlrU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uJlrU.png" alt="enter image description here" /></a></p>
  <p>Well, I get the above chart for MW04, but the charts for the other two monitoring wells look like this:</p>
  <p><a href="https://i.stack.imgur.com/EQPZL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EQPZL.png" alt="enter image description here" /></a></p>
  <p>It appears the date axis min/max are being automatically calculated, but are calculated wrong for MW02 and MW03, but correctly for MW04.</p>
  <p>Any ideas on why this might be? Or any other tips for working with date axis for charts with openpyxl?</p>
  <p>Thanks,</p>