matplotlib

animation moving point error

匆匆过客 提交于 2021-01-28 02:08:40
问题 I am a beginner to Python. I'm trying to make an animation of a point moving in the horizontal direction. But, when I ran the code I received the below error: TypeError: 'PathCollection' object is not iterable I have no idea how to fix it. #---------------------------------------------------------------------- import numpy as np import matplotlib import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation Acc_11 = [1,2,3,4,6,7] lenAcc11 = len(Acc_11) Acc_12 = [2,2,2,2,2,2]

Fixed size rectangle in matplotlib?

孤人 提交于 2021-01-28 02:02:29
问题 Is there any way to plot a rectangle spanning the entire length of the X-axis but with a fixed and static height of, say 20 pixels? The height of the rectangle should remain a constant number of pixels regardless of zooming or resizing the plot. I've spent hours looking for a solution to this but I just cannot make it work. Any suggestions? Thanks 回答1: You want to create a rectangle, positionned in axes coordinates, and horizontally sized in axes coordinates as well, but with a height in

Matplotlib: figure.add_axes convert from x,y to relative coordinates

亡梦爱人 提交于 2021-01-28 02:00:13
问题 I am working on a self-organizing map that I want to show as a hexagonal lattice with spider charts representing the weight vector/neuron in the corresponding cells and have been able to create a hexagonal grid via the following: def hex_plot(ws,a=1): """ plots a m (rows) x n (cols) hexagonal grid with offset rows where a is the hexagon's side length and m and n are determined by the first two dimensions of the weight vectors ws """ m,n,_ = ws.shape offsety = .75 * 2*a offsetx = numpy.sqrt(3)

read and plot multiple txt files in python

夙愿已清 提交于 2021-01-28 01:44:25
问题 I have some output files ie frequency1 .txt , frequency2 .txt and so on (till 21). In each txt files I am having 10 columns and suppose n rows , now I need to plot column 2 and column 3 for all these txt files .I am able to plot for a single txt file import numpy as np from matplotlib import pyplot as plt data=np.loadtxt('frequecy1.txt') pl.plot(data[:,1],data[:,2],'bo') X=data[:,1] Y=data[:,2] plt.plot(X,Y,':ro') plt.ylim((0,55000)) plt.show() How would I plot all the files? 回答1: First,

Legend not showing when plotting multiple seaborn plots

天大地大妈咪最大 提交于 2021-01-28 01:05:54
问题 I typically don't have problems with matplotlib legend, but this is the first time I am using it with multiple seaborn plots, and the following does not work. fig = plt.figure(figsize=(10,6)) a =sns.regplot(x='VarX', y='VarY1', data=data) b = sns.regplot(x='VarX', y='VarY2', data=data) c = sns.regplot(x='VarX', y='VarY3', data=data) fig.legend(handles=[a, b, c],labels=['First','Second','Third']) fig.show() What am I doing wrong? 回答1: seaborn.regplot returns an axes. You cannot create a legend

Draw now and Matplotlib

瘦欲@ 提交于 2021-01-28 00:27:07
问题 I am currently working on a project that involves taking analog readings, and mapping them real time on a graph. So to complete this I am running a photo resister through an Arduino Analog port and am reading that data via python 3.4.3. On the python side I have maplotlib, and drawnow installed. The code as it is shown below will plot the first data marker that the resistor will read, but will not update it real time. However if I change the resistance and then restart the program it will

Python surface fitting of variables of different dimensionto get unknown parameters?

。_饼干妹妹 提交于 2021-01-27 23:43:39
问题 I have a function that includes x and y as independent variables and I want to fit the parameters to the data and function and plot a surface figure. I saw that if the variables have two different dimensions, I can use np.meshgrid(x,y) , but then how do I find the parameters a,b,c? My code looks like this: import matplotlib.pyplot as plt from scipy.optimize import curve_fit import numpy as np x = np.array([1,0.5,0.33,0.25,0.2]) y = np.array([1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3,1e-2,1e-1,1e0

How can I specify the color for a partial histogram patch?

半城伤御伤魂 提交于 2021-01-27 23:37:18
问题 I would like to produce the following graph Note that one bar is partially blue and partially teal. This is what I'm trying to reproduce import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Rectangle # plt parameters plt.rcParams['figure.figsize'] = (10.0, 10.0) plt.style.use('seaborn-dark-palette') plt.rcParams['axes.grid'] = True plt.rcParams["patch.force_edgecolor"] = True # data np.random.seed(365) replicates = np

Graph with multiple x and y axis using Matplotlib

女生的网名这么多〃 提交于 2021-01-27 23:12:11
问题 As I checked with the Matplotlib document and other resources. I got that when multiple axis were created they are not depend on each other and we can plot the multiple line as per different axis. But I need to plot the graph like two Y-axis contains with the temperature as (Celsius and Fahrenheit) and need to plot only one single line related to that so with 1st axis user able to check Celsius and with 2nd axis Fahrenheit. with x-axis as range (1 -24 hr). Suggestions are most welcome. 回答1:

2x2 Contourf plots sharing the same colorbar

对着背影说爱祢 提交于 2021-01-27 22:50:41
问题 I would like to add a single color bar on the right side of the following 2x2 plot. import matplotlib.pyplot as plt import numpy as np x = np.linspace(-np.pi*2, np.pi*2, num=50) y = np.linspace(-np.pi*2, np.pi*2, num=50) def fun(x, y, pw1, pw2): X,Y = np.meshgrid(x, y) return (X, Y, np.cos(X*Y)**pw1 + np.sin(X+Y)**pw2) X, Y, f01 = fun(x,y,0,1) X, Y, f10 = fun(x,y,1,0) X, Y, f11 = fun(x,y,1,1) X, Y, f12 = fun(x,y,1,2) fig1, axs = plt.subplots(nrows=2,ncols=2, figsize=(8,8),sharex='col', sharey