matplotlib

Python 3.7: Fill area between two lines with different x-axes values that zigzag a lot

限于喜欢 提交于 2021-02-11 18:07:11
问题 I have a dataset whose uncertainty I would like to represent as a filled region around the main plot. The errors are large in the x-axes direction, so I have not been able to use plt.fill_between(x, y1, y2) , which requires a common set of x-axes. I have tried using plt.fill(np.append(x1, x2[::-1])) as suggested elsewhere on this website, but because my data zigzags up and down a lot, the filled regions end up looking like nodes (see attached figure). What I would like to accomplish is a

Step function with linear inteval in numpy

故事扮演 提交于 2021-02-11 17:42:34
问题 I want to implement for a step function in numpy with the definition: 回答1: Since the other answer does not implement the function in the question, here is a correct soluton: import numpy as np import matplotlib.pyplot as plt x= np.linspace(0., 50., 1001) f = lambda x0, x1: np.piecewise(x, [x < x0, (x >= x0) & (x <= x1), x > x1], [0., lambda x: x/x0, 1.]) plt.plot(x, f(10, 30)) plt.show() 来源: https://stackoverflow.com/questions/57516274/step-function-with-linear-inteval-in-numpy

Step function with linear inteval in numpy

别等时光非礼了梦想. 提交于 2021-02-11 17:41:41
问题 I want to implement for a step function in numpy with the definition: 回答1: Since the other answer does not implement the function in the question, here is a correct soluton: import numpy as np import matplotlib.pyplot as plt x= np.linspace(0., 50., 1001) f = lambda x0, x1: np.piecewise(x, [x < x0, (x >= x0) & (x <= x1), x > x1], [0., lambda x: x/x0, 1.]) plt.plot(x, f(10, 30)) plt.show() 来源: https://stackoverflow.com/questions/57516274/step-function-with-linear-inteval-in-numpy

Importing & running matplotlib via CGI

别等时光非礼了梦想. 提交于 2021-02-11 17:28:19
问题 I'm having some dramas with matplotlib and CGI, despite a night spent searching for solutions. In brief, I'm running Python2.7 with matplotlib through a Bluhost server. I have want a simple script to display an image, but it's getting stuck on the import of matplotlib: import cgitb, os cgitb.enable() import matplotlib The traceback yields the following: : No module named matplotlib args = ('No module named matplotlib',) message = 'No module named matplotlib' Any clues? It seems most of the

Pyplot either freezes or does not show in interactive mode

≡放荡痞女 提交于 2021-02-11 16:59:15
问题 I am making a script that fetches data every minute and then tries to show that in a matplotlib pyplot. I have three main files: control_cycle.py to control the loop and interact with other functions, api_connect.py(ac) to communicate with server and fetch data and graph_stock.py (gs) with a function to graph the data. So it is important that all time control and waiting is controller by control_cycle.py. However I just can't get the plotting to function properly. I have tried over a dozen

Pyplot either freezes or does not show in interactive mode

痞子三分冷 提交于 2021-02-11 16:58:44
问题 I am making a script that fetches data every minute and then tries to show that in a matplotlib pyplot. I have three main files: control_cycle.py to control the loop and interact with other functions, api_connect.py(ac) to communicate with server and fetch data and graph_stock.py (gs) with a function to graph the data. So it is important that all time control and waiting is controller by control_cycle.py. However I just can't get the plotting to function properly. I have tried over a dozen

Adding image generated from another library as inset in matplotlib

梦想与她 提交于 2021-02-11 16:52:23
问题 I've generated a network figure using vedo library and I'm trying to add this as an inset to a figure generated in matplotlib import networkx as nx import matplotlib.pyplot as plt from vedo import * from matplotlib.offsetbox import OffsetImage, AnnotationBbox G = nx.gnm_random_graph(n=10, m=15, seed=1) nxpos = nx.spring_layout(G, dim=3, seed=1) nxpts = [nxpos[pt] for pt in sorted(nxpos)] nx_lines = [(nxpts[i], nxpts[j]) for i, j in G.edges()] pts = Points(nxpts, r=12) edg = Lines(nx_lines).lw

Adding image generated from another library as inset in matplotlib

微笑、不失礼 提交于 2021-02-11 16:50:04
问题 I've generated a network figure using vedo library and I'm trying to add this as an inset to a figure generated in matplotlib import networkx as nx import matplotlib.pyplot as plt from vedo import * from matplotlib.offsetbox import OffsetImage, AnnotationBbox G = nx.gnm_random_graph(n=10, m=15, seed=1) nxpos = nx.spring_layout(G, dim=3, seed=1) nxpts = [nxpos[pt] for pt in sorted(nxpos)] nx_lines = [(nxpts[i], nxpts[j]) for i, j in G.edges()] pts = Points(nxpts, r=12) edg = Lines(nx_lines).lw

Plotting many columns from a csv file

烂漫一生 提交于 2021-02-11 15:58:55
问题 Imagine I have a very big csv file with 500 rows and 500 columns. Part of the data shown : a small section of my data I cannot delete the first couple of rows from my file but I can omit them using "skiprows" while reading the file. Then I want to plot my data and all methods that I try fail. I actually get a plot if I just use 'plot()" command but what I want is to have the first column as my x data and the rest of 499 columns as my y data. Could you please help me with this? 回答1: If df is

Matplotlib - smooth a line

Deadly 提交于 2021-02-11 15:45:51
问题 I'm looking for an advice on how to smoothen a trend line. This is the code: import pandas as pd from numpy import random #Generating the data frame df = pd.DataFrame(data = random.randn(5,4), index = ['A','B','C','D','E'], columns = ['W','X','Y','Z']) df['W'] = ['10/01/2018 12:00:00','10/03/2018 13:00:00', '10/03/2018 12:30:00','10/04/2018 12:05:00', '10/08/2018 12:00:15'] pd.to_datetime(df['W']) print(df.head()) #Plotting hte graph fig, ax = plt.subplots() df.plot(x="W", y="X", ax=ax, color