def register_pandas_datetime_converter_if_needed(): # based on https://github.com/pandas-dev/pandas/pull/17710 global _registered if not _registered: from pandas.tseries import converter converter.register() _registered = True
def plot(self, date1: str, date2: str, data='Global Horiz'): df = self.loading() converter.register() d1 = datetime.strptime(date1, '%Y-%m-%d') d2 = datetime.strptime(date2, '%Y-%m-%d') df2plot = df.loc[d1:d2] sns.set(style="darkgrid") f, ax = plt.subplots(figsize=(10, 5)) sns.lineplot(x=df2plot.index, y=df2plot[data]) # Removing top and right borders ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) # Finalize the plot sns.despine(bottom=True) plt.setp(f.axes, xticks=[], xlabel='Interval\nfrom: {0}\nto: {1}'.format(date1, date2), ylabel='Solar Irradiation (W/m²)') plt.tight_layout(h_pad=2) plt.savefig("output.png") print('Image saved.')
def test_old_import_warns(self): with tm.assert_produces_warning(FutureWarning) as w: from pandas.tseries import converter converter.register() assert len(w) assert ('pandas.plotting.register_matplotlib_converters' in str(w[0].message))
def main(): # NB: https://github.com/pydata/xarray/issues/1661#issuecomment-339525582 from pandas.tseries import converter converter.register() p = parse_cmdline() common.set_logger(logging.DEBUG if p.verbose else logging.INFO, p.log, loggers={"FCDR_HIRS", "typhon"}) plot(p)
def test_date2num_dst_pandas(): # Test for github issue #3896, but in date2num around DST transitions # with a timezone-aware pandas date_range object. pd = pytest.importorskip('pandas') from pandas.tseries import converter converter.register() def tz_convert(*args): return pd.DatetimeIndex.tz_convert(*args).astype(object) _test_date2num_dst(pd.date_range, tz_convert)
def heatmap(*args, classes=None, cmap=DEFAULT_DISCRETE_CMAP, **kws): """j24.visualization.heatmap wrapper for sounding data""" # This is needed because of a bug in pandas 0.21 from pandas.tseries import converter converter.register() fig, ax = vis.heatmap(*args, cmap='jet', **kws) fmt_m2km(ax.yaxis) ax.set_ylabel('Height, km') if classes is not None: vis.class_colors(classes, ax=ax, cmap=cmap) return fig, ax
def register_pandas_datetime_converter_if_needed(): # based on https://github.com/pandas-dev/pandas/pull/17710 global _registered if not _registered: try: from pandas.plotting import register_matplotlib_converters register_matplotlib_converters() except ImportError: # register_matplotlib_converters new in pandas 0.22 from pandas.tseries import converter converter.register() _registered = True
import pandas as pd import numpy import matplotlib.pyplot as plt import argparse from pandas.tseries import converter converter.register() if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--assessments', type=str, default="assessments.csv", help="CSV file input") parser.add_argument('--parcel', type=str, help="The parcel to compare", required=False) args = parser.parse_args() df = pd.read_csv(args.assessments) df['Sale Date'] = pd.to_datetime(df['Sale Date'], format='%m/%d/%Y') parcel = df.loc[df['Parcel Id'] == args.parcel] ax = df.plot(kind='scatter', x='Lot Area', y='County Land Value') parcel.plot(kind='scatter', x='Lot Area', y='County Land Value', color='red', ax=ax) ax = df.plot(kind='scatter',
from .sankey import * # noqa (API import) from .stats import * # noqa (API import) from .tabular import * # noqa (API import) from .renderer import MPLRenderer mpl_ge_150 = LooseVersion(mpl.__version__) >= '1.5.0' if pd: try: from pandas.plotting import register_matplotlib_converters register_matplotlib_converters() except ImportError: from pandas.tseries import converter converter.register() def set_style(key): """ Select a style by name, e.g. set_style('default'). To revert to the previous style use the key 'unset' or False. """ if key is None: return elif not key or key in ['unset', 'backup']: if 'backup' in styles: plt.rcParams.update(styles['backup']) else: raise Exception('No style backed up to restore') elif key not in styles:
import datetime import numpy as np from pandas.util.decorators import cache_readonly import pandas.core.common as com from pandas.core.index import MultiIndex from pandas.core.series import Series, remove_na from pandas.tseries.index import DatetimeIndex from pandas.tseries.period import PeriodIndex from pandas.tseries.frequencies import get_period_alias, get_base_alias from pandas.tseries.offsets import DateOffset try: # mpl optional import pandas.tseries.converter as conv conv.register() except ImportError: pass def _get_standard_kind(kind): return {'density' : 'kde'}.get(kind, kind) def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False, diagonal='hist', marker='.', **kwds): """ Draw a matrix of scatter plots. Parameters ---------- alpha : amount of transparency applied
""" Functions for generating nice lidar profile graphs """ # get matplotlib with agg backend for drawing graphs on servers with # no display import matplotlib matplotlib.use('Agg') matplotlib.rcParams['figure.figsize'] = (15, 7) from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure import matplotlib.pyplot as plt # see here: https://matplotlib.org/faq/howto_faq.html#plot-numpy-datetime64-values from pandas.tseries import converter as pdtc pdtc.register() # useful stuff import xml, rasppy import datetime as dt import numpy as np import xarray as xr from io import BytesIO # matplotlib tools for calculating tickmark locations -- I'm using # these to find nice windbarb intervals from matplotlib.ticker import MaxNLocator from matplotlib.dates import AutoDateLocator, num2date # and this is needed to help monkey patch the barbs function from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY) MICROSECONDLY = SECONDLY + 1