matplotlib

Fit Ellipse over 2D data using Python and matplotlib

本秂侑毒 提交于 2021-01-29 05:44:12
问题 I am trying to fit an ellipse over my different sets of 2D points using matplotlib. I'm using the ellipse fitting functions from here, and here's the code. from matplotlib.patches import Ellipse import matplotlib.pyplot as plt import numpy def fitEllipse(x,y): x = x[:,np.newaxis] y = y[:,np.newaxis] D = np.hstack((x*x, x*y, y*y, x, y, np.ones_like(x))) S = np.dot(D.T,D) C = np.zeros([6,6]) C[0,2] = C[2,0] = 2; C[1,1] = -1 E, V = eig(np.dot(inv(S), C)) n = np.argmax(np.abs(E)) a = V[:,n]

Loop to graph into a Dict Python MATPLOTLIB

六眼飞鱼酱① 提交于 2021-01-29 05:23:36
问题 What i'm trying to do here is to make a loop to create multiple graphs of dicts. I looped to execute univariate rolling window regressions and I stored the COEFS and the R_SQ of each variable in a DICT. the DICT itsel got 23 sub DICT each containing my a series of coefficients and rsquareds from 2008 to 2020 (4580 obs.) It goes like this (for visualisation): data1 BE10USD params - const & coef r_sq BE30CAD params - const & coef r_sq SWAP1YUSD params - const & coef r_sq And on, my dict is

How to find number of self intersection points on 2D plot?

风格不统一 提交于 2021-01-29 05:03:01
问题 I have two numpy arrays x and y : x = [-256.70946838 -188.26946838 -83.86946838 29.81053162 131.89053162 213.67053162 271.09053162 315.17053162 310.53053162 296.03053162 252.53053162 184.67053162 82.59053162 -33.40946838 -139.54946838 -213.78946838 -271.20946838 -317.02946838 -310.64946838 -298.46946838 -256.70946838] y = [ 9.71224758e-02 -3.19097822e-02 -4.80388145e-02 6.48644113e-02 -3.19097822e-02 9.71224758e-02 -1.57807500e-02 6.48644113e-02 -4.02877524e-01 -1.93200105e-01 6.48644113e-02

利用ArcGIS和Python计算中国各省路网密度

本秂侑毒 提交于 2021-01-29 04:35:31
ArcGIS 相交 利用ArcGIS里面的相交工具,每个省把路标识了。 计算几何 分别计算路网的长度和各省的面积。 Python 利用Python对属性数据进行处理 导入相关模块 ## 导入相关模块 import pandas as pd import geopandas as gpd import matplotlib.pyplot as plt %matplotlib inline 解决中文乱码 plt.rcParams['font.family'] = ['sans-serif'] plt.rcParams['font.sans-serif'] = ['SimHei']# 替换sans-serif字体为黑体 plt.rcParams['axes.unicode_minus'] = False # 解决坐标轴负数的负号显示问题 数据读取 regibns = gpd.GeoDataFrame.from_file("省级行政区.shp") regibns = regibns[["NAME","AREA","geometry"]] regibns["AREA"] = regibns["AREA"]/1000000 regibns.head() regibns.plot() ! road = gpd.GeoDataFrame.from_file("道路密度.shp") road

catplot(kind=“count”) is significantly slower than countplot()

旧巷老猫 提交于 2021-01-29 04:35:00
问题 I am working on a fairly large dataset (~40m rows). I have found that if I call sns.countplot() directly then my visualisation plots really quickly: %%time ax = sns.countplot(x="age_band",data=acme) However if I do the same visualisation using catplot(kind="count") then the speed of execution slows down dramatically: %%time g = sns.catplot(x="age_band",data=acme,kind="count") Is there a reason for such a large performance difference? Is catplot() doing some sort of conversion on my data

Looping over data and creating individual figures

北慕城南 提交于 2021-01-29 04:13:00
问题 I'm looping over a list of names of different molecules and trying to generate individual figs for each of them. But for each successive molecule the new figures have all the previous data on as well. I've printed the data after I've gathered it and for each loop it's showing the correct amount. Here's my full code import matplotlib import matplotlib.pyplot as plt import numpy as np mols = ["P_Z1", "P_Z2", "TT_Z1", "TT_Z2", "TP_Z1", "TP_Z2"] for mol in mols: en = [] den = [] with open (mol+

plot time series dataframe and mark certain points using pandas and matplotlib

五迷三道 提交于 2021-01-29 04:11:10
问题 I have a dataframe storing a time series, which looks like as follows. How to plot it using time column as x-axis . Moreover, if I want to mark certain points between a given time period, e.g., 2014-11-18 to 2015-1-30 . How to do that using matplotlib ? This is what I did, but it appears pretty small, and how to add some marks over the certain time period? 回答1: the easiest way to do this is to plot twice, the second plot having the extra style. Regarding the plot size, you can control the

Python Audio fftpack: Filter noise signal and graph it?

强颜欢笑 提交于 2021-01-29 03:57:40
问题 So I'm follow a tutorial where we create a signal and filter the noise using fftpack. Problem 1: I'm trying to plot the filtered and unfiltered signal noise on a graph so that I can see them side by side. Getting error: Warning (from warnings module): File "C:\Python39\lib\site-packages\numpy\core_asarray.py", line 83 return array(a, dtype, copy=False, order=order) ComplexWarning: Casting complex values to real discards the imaginary part I think this is causing the error: y = sig x = time

get the key value when calling matplolib pyplot waitforbuttonpress()

杀马特。学长 韩版系。学妹 提交于 2021-01-29 03:52:50
问题 matplotlib pyplot has a function called waitforbuttonpress() which will return either True or False depending on whether a keyboard or mouse event is received within a graph. As such mouse events are returned by waitforbuttonpress() even if the user interact with the figure using normal graph tools (such as zooming), the only way to use this function is as follows: (assuming the zooming function should be available) while not plt.waitforbuttonpress(): pass #ignore mouse events use by zomming

Resize subplots using seaborn

依然范特西╮ 提交于 2021-01-29 03:14:51
问题 I have just recently started to use matplotlib and seaborn to plot my graphs. This is the code that I wrote so far count = 1 l=[13,0,47,29,10] plt.figure(figsize=(30,40)) for ww in l: temp_dict = defaultdict(list) entropies = list() for k,v in df.ix[ww].iteritems(): e = 0 for i in v: temp_dict[k].append(float(i)) if not float(i) == 0: e += -1.0*float(i)*log10(float(i)) entropies.append(e) y = entropies x=(range(len(entropies))) slope, intercept, r_value, p_value, std_err = stats.linregress(x