The following example shows you how to draw multiple subplots with different widths and heights. It also tells you the answers to some other questions. How to do technical analysis of a stock? How to draw double y-axis plot? How to set height of a subplot? import numpy as np import talib import emoji import ..
Category : Numpy
We often need to draw multiple similar maps using the same colorbar. A good way is to use the AxesGrid from the Cartopy package. Below is one of my examples of sharing colorbars for 4 submaps. This example can also answer other questions: How to add ocean, river, lakes,coastline and province border to a map? ..
If you have grid or point data and polygon shapefiles for longitude and longitude. Using geopandas and shapely it’s easy to find grids or points in specific polygons. import geopandas as gpd import pandas as pd import numpy as np import matplotlib.pyplot as plt from shapely.geometry import Point # US state polygon shape file US_states=gpd.GeoDataFrame.from_file(‘states_province_shapefile\cb_2018_us_state_20m\cb_2018_us_state_20m.shp’) ..
We often use running averages to remove noise from time series. Below is a simple python code to do this easily. import numpy as np from numpy import random import matplotlib.pyplot as plt # your data data = random.random(size=(1,100)) # set window kernel_size = 10 # window width is 10 # set weight, you can ..
Xarray data is often used in huge spatial datasets. We often need to fetch data in subregions. The following example shows you how to extract subset data from a large xarray. import numpy as np import xarray as xr #set the sub domain box min_lon = 100 min_lat = 20 max_lon = 150 max_lat = ..
Method to write and read a single N-Dimension numpy array to a .npy file. Sample code import numpy as np #write a 3-dimension varaible trend38 np.save(‘indexes_trend38_sens_slope.npy’,trend38) #read the 3-dimention variable to trend38 (use different name is ok) trend38=np.load(‘indexes_trend38_sens_slope.npy’) My original full version code:Indexes_ERA5_GreatLakesRegion_sens_s..
pr_data[‘PrTot’]=xr.DataArray(PrTot.astype(np.float32), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘R1mm’]=xr.DataArray(R1mm.astype(np.int16), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘R10mm’]=xr.DataArray(R10mm.astype(np.int16), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘R20mm’]=xr.DataArray(R20mm.astype(np.int16), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘SDII’]=xr.DataArray(SDII.astype(np.float32), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘Rx1day’]=xr.DataArray(Rx1day.astype(np.float32), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) pr_data[‘Rx5day’]=xr.DataArray(Rx5day.astype(np.float32), coords=pr_data.coords, dims=pr_data.tp.dims, attrs=pr_data.attrs) See example code: /media/Data1/OnClimate/Precipitation_indexes_EAR5_GreatLakesRegion.ipynb Pay attention to line: dims=pr_dat..
Introduction This article includes some Python functions for calculating the core climate extreme index. I post them here for my future reference, and share them with people who are interested in python or climate change. No guarantee of accuracy. The definitions of the core climate extreme indices 1.Description of Climate Extreme Indexes by OCDP 2.Definitions ..
Following is my python code to plot stock chart on a background image from local file. The code is not optimal, I will improve it later. Hope it be useful. The example is plot ABX.TO.csv (download from yahoo finance) data on a logo collection image (my file:/media/Data1/XIU/AACodes/NASDAQ_stocks.png). Code # plot stock data with a background-image ..
This example is used for fitting world covid-19 cases number import numpy as np import pandas as pd from datetime import datetime from lmfit import Minimizer, Parameters, report_fit import chart_studio.plotly as py import cufflinks as cf def Cauchy_cumulative_hazard_fit(x,loc,scale,decaybase): decayterm=np.power(decaybase,(x-loc)) decayterm[np.whe..