FAQ Database Discussion Community

backend not being reset by matplotlibrc.py

python,osx,matplotlib,backend
I'm having trouble getting matplotlib plots to appear in front of my other windows - this is apparently a macosx backend problem. However, after making the following changes in ~/.matplotlib/matplotlibrc.py: #backend : macosx backend : TkAgg I run this command in python import matplotlib print matplotlib.rcParams['backend'] and it returns: MacOSX...

How to reshape a networkx graph in Python?

python,matplotlib,nodes,shape,networkx
So I created a really naive (probably inefficient) way of generating hasse diagrams. Question: I have 4 dimensions... p q r s . I want to display it uniformly (tesseract) but I have no idea how to reshape it. How can one reshape a networkx graph in Python? I've seen...

plot a matplotlib line with a given slope

python,matplotlib,plot,linear
I have a scatter plot with X axis from 150-360 and y from 50-260 The slope of the linear fit line is -40 degrees What I want is a I can draw another line at -45 degrees to act as a guide to show that the actual line is "close"...

python,matplotlib,plot
I have a question about add shading in my figure. I need to shading all subplot like the picture below, how to do it in Python?

can't chart what I want to chart with .hist() in Pandas

python,pandas,matplotlib,histogram
simple question. hopefully it's really quite basic. I have a pandas dataframe named firstperiod and a column named megaball. The range of the values in megaball are from 1 to 25, and this line of code: print firstperiod.megaball.value_counts().sort_index() gives me this, which is what I want to see (the #...

how to create a 3D height map in python

python,matplotlib,plot,3d,surface
I have a 2D array Z that stores the height at that element's position. Other than using the method here in which I need to create array X and Y with the same size as Z, are there any simpler methods to create a 3D height map? The 3D surface...

How do I make a decaying oscilating function in python?

python,numpy,matplotlib,graph,physics
I have a code in python to represent the energy decay in a damped oscilator, it reads like this: def E(wt, Q): return (np.e**(-x/Q))*(1-(1/2*Q)*np.sin(2*x)) x = np.linspace(0,20,1000) y0 = E(x,2) y1 = E(x,4) y2 = E(x,8) y3 = E(x,16) plt.plot(x, y0, 'p', label=r'$Q=2$') plt.plot(x, y1, 'r', label=r'$Q=4$') plt.plot(x, y2, 'g',...

How to index List/ numpy array in order to plot the data with matplotlib

python,numpy,matplotlib
I have a function f(x,t) = cos(t)*t + x and i want to display the change of the result over the width x and time t at discretised time steps t_i and discretised width steps x_j. Now I am a while here on SX and feel really embarrassed to only...

Matplotlib subplot y-axis scale overlaps with plot above

python,matplotlib
I am trying to plot 3 subplots without any white space between them. The default y axis ticklabels use a scale displayed to the top right of the y axis (1e-8 in the example below), which would be fine except for the lower two plots this overlaps with the plot...

How do I change the format of the axis label in matplotlib

matplotlib,axis-labels
If I plot a log scale graph, matplotlib gives me the nice looking entries 105, 106, ... For readability I would however prefer the form 1e5, 1e6, ... Can I directly set the axis properties to behave that way? I rather ugly hack would be: import matplotlib.pyplot as plt import...

manipulating top and bottom margins in pyplot horizontal stacked bar chart (barh)

python,matplotlib,margins
I'm trying to plot a horizontal stacked bar chart but get annoyingly big margins on top and bottom. I would like to get rid of that or control the size. Here is an example code and fig: from random import random Y = ['A', 'B', 'C', 'D', 'E','F','G','H','I','J', 'K'] y_pos...

Arrange line in front of bars in Matplotlib plot with double y axes

python,matplotlib,plot
I want to plot a graph with two y axes, and I want the left y axis to show a line according to which the x axis is sorted, and the right y axis to show bars. My problem is that the secondary y axis hides the first y axis,...

Creating a hexplot

r,matlab,matplotlib,gnuplot,matlab-figure
I am trying to create a figure like the one depicted in the third column of the following image: Link for the image in case of backup. Basically I have x and y positions of 200 particles and I have the MSD data for these 200 positions. I'd like MSD...

Python Scatter Plot with Colorbar and Legend Issues

python,matplotlib,legend,scatter-plot
I'm working with a pretty simple example. I create three scatter plots on the same set of axes, and each data set I plot has a different associated colormap. However, the legend does not look as I'd want it to; why is this? import numpy as np import matplotlib.pyplot as...

Matplotlib heatmap: Image rotated when heatmap plot over it

I am trying to plot a heatmap on top of an image. What I did: import matplotlib.pyplot as plt import numpy as np import numpy.random import urllib #downloading an example image urllib.urlretrieve("http://tekeye.biz/wp-content/uploads/2013/01/small_playing_cards.png", "/tmp/cards.png") #reading and plotting the image im = plt.imread('/tmp/cards.png') implot = plt.imshow(im) #generating random data for the histogram...

Matplotlib subplot2grid plotting IndexError in pandas 0.16.1

python,pandas,matplotlib,histogram
I have (5) pandas series i'm trying to plot on (5) graphs. i want to have them so that they look like this format with the 5th chart on the last row by itself, centered (don't focus on the contents of the charts, just the positioning) But in pandas 0.16.1,...

python matplotlib, get pixel value after colormap applied

python,matplotlib,imshow
I display an image with matplotlib using imshow(). imshow apply a LUT and I would like to retrieve a pixel value (at x, y) after LUT applied. For exemple I have a full black image I display with imshow The image becomes yellow (cause of LUT) get_pixel(x, y) -> yellow...

Matplotlib figure not updating on data change

python,matplotlib,pyqt4
I'm implementing an image viewer using matplotlib. The idea is that changes being made to the image (such as filter application) will update automatically. I create a Figure to show the inital image and have added a button using pyQt to update the data. The data does change, I have...

How can I draw a scatter plot with contour density lines in polar coordinates using Matplotlib?

python,matplotlib,scatter-plot,polar-coordinates
I am trying to make a scatter plot in polar coordinates with the contour lines superposed to the cloud of points. I am aware of how to do that in cartesian coordinates using numpy.histogram2d: # Simple case: scatter plot with density contours in cartesian coordinates import matplotlib.pyplot as pl import...

Matplotlib Crash When Figure 1 not Closed Last

python-3.x,matplotlib
I am plotting mutliple figures using Matplotlib using Python 3.4. When the multiple figures are open and I close the windows closing the first figure last (ie once all other figures are closed) python does not crash. If, however, I close the first figure that was plotted first and then...

How to use meshgrid with large arrays in Matplotlib?

python,arrays,matplotlib,scipy,scikit-learn
I have trained a machine learning binary classifier on a 100x85 array in sklearn. I would like to be able to vary 2 of the features in the array, say column 0 and column 1, and generate contour or surface graph, showing how the predicted probability of falling in one...

pandas matplotlib .plot(kind='hist') vs .plot(kind='bar') issue

python,pandas,matplotlib,histogram,bar-chart
I have a pandas dataframe named firstperiod and a column named megaball. The range of the values in megaball are from 1 to 25, and this line of code: print firstperiod.megaball.value_counts().sort_index() gives me this, which is what I want to see (the # of occurrences per possible value) 1 12...

Python returns instance instead of array

python,numpy,matplotlib,plot,instance
The structure of my program is simple. I have two .py files, say file1.py and file2.py. file1 is UI, file2 is calculations. When a button is pressed, file1 sends the user input to file2 and file2 does calculations and then it is supposed to return an array to file1 so...

Turn off scientific notation and offset globally

python,matplotlib,plot
I have been trying for several hours to globally turn off scientific notation and the offset in matplotlib. my attempt at a solution import matplotlib as mpl import matplotlib.pyplot as plt The documentation says: set the rcParam axes.formatter.useoffset=False to turn it off globally, or set a different formatter. mpl.rcParams.formatter.useoffset =...

term frequency over time: how to plot +200 graphs in one plot with Python/pandas/matplotlib?

python,matplotlib,plot,nlp
I am conducting a textual content analysis of several web blogs, and now focusing on finding emerging trends. In order to do so for one blog, I coded a multi-step process: looping over all the posts, finding the top 5 keywords in each post adding them to a list, if...

How do I install an external module from a wheel?

python,matplotlib,six
I'm trying to run someone else's script in Python 2.7 on Win7x64 (but 32-bit Python - I need it to be 2.7 to run pyserial, apparently). It starts with the following lines: import os import matplotlib.pyplot as plt import numpy as np from pylab import * from mpl_toolkits.mplot3d import Axes3D...

Need workaround to treat float values as tuples when updating “list” of float values

python-2.7,matplotlib,computer-science,floating-point-conversion
I am finding errors with the last line of the for loop where I am trying to update the curve value to a list containing the curve value iterations. I get errors like "can only concatenate tuple (not "float) to tuple" and "tuple object has no attribute 'append'". Does anyone...

How to draw a filled arc in matplotlib

python,matplotlib
In matplotlib, I would like draw an filled arc which looks like this: The following code results in an unfilled line arc: import matplotlib.patches as mpatches import matplotlib.pyplot as plt fg, ax = plt.subplots(1, 1) pac = mpatches.Arc([0, -2.5], 5, 5, angle=0, theta1=45, theta2=135) ax.add_patch(pac) ax.axis([-2, 2, -2, 2]) ax.set_aspect("equal")...

Tricontour with triangle values

python,matplotlib
I would like to produce a tricontour plot similar to these with matplotlib. The difference between these examples and my situation is that I don't have the values of my function in the grid points: they are defined in my triangles (e.g. in the centroid of each triangle). I would...

IOError for savefig JPG in matplotlib

python,matplotlib,jpeg,canopy
I am trying to save a JPG and having issues. The following gives "IOError: encoder error -2 when writing image file" import matplotlib.pyplot as plt plt.plot([1, 2]) plt.savefig('image.jpg') It works with png so I tried to: pip install pillow as suggested here but it was already installed in Canopy. It...

Making networkx plot where edges only display edited numeric value, not field name

python,matplotlib,networkx
I want to make it so I can put a $on the weight number and set it as the edge text. Can someone smart tell me the trick to do this? For example if the weight of an edge is 20, I want the edge text to be... Plot a graph, clear its axes, then plot a new graph python,python-3.x,matplotlib I'm trying to do the following: create a figure, plot a graph on it, then in 3 seconds clear its axes. When that happen a new graph should be plotted on the same figure and it should be updated on the screen. Something like: import matplotlib.pyplot as plt import time... Pandas plot dataframe as scatter complains of unknown item python,pandas,matplotlib I have thousands of data points for two values Tm1 and Tm2 for a series of text lables of type : Tm1 Tm2 ID A01 51 NaN A03 51 NaN A05 47 52 A07 47 52 A09 49 NaN I managed to create a pandas DataFrame with the values from... “Replot” a matplotlib inline plot in a IPython notebook python,matplotlib,ipython,visualization,scientific-computing if I work on a matplotlib inline plot in an ipython notebook like this: figure = plt.figure() ax = figure.gca(projection="3d") graph = np.empty([len(thetaYield),3]) for g, tY in zip(graph, thetaYield): sample = HWtoPS(xiYield, rhoYield, tY) g[...] = sample[:] ax.plot(graph[:,0],graph[:,1], graph[:,2]) plt.show() the plot is drawn inline in my notebook as it... Read CSV and plot colored line graph python,csv,matplotlib,graph,plot I am trying to plot a graph with colored markers before and after threshold value. If I am using for loop for reading the parsing the input file with time H:M I can plot and color only two points. But for all the points I cannot plot. Input akdj 12:00... Update color of an already plotted graph? python,python-3.x,matplotlib I wonder if it is possible to update a parameter such as the line color of an already plotted graph that doesn't wrap on destroying the graph and creating another one. Example: I plot a graph then I create a few horizontal green lines on it by clicking. Now I... How to show minor tick labels on log-scale with Matplotlib python,matplotlib Does anyone know how to show the labels of the minor ticks on a logarithmic scale with Python/Matplotlib? Thanks!... Python - matplotlib - PyQT: plot to QPixmap python,matplotlib,plot,pyqt I want to visualise matplotlibs colormaps (similar to http://matplotlib.org/examples/color/colormaps_reference.html) and use it as QPixmaps in PyQt widgets. The idea is to create the plots in matplotlib without actually showing it (or saving it to a file) and convert it to a QPixmap. The solution offered here (Python - matplotlib -... Adding a matplotlib patch to inline axis twice in an iPython notebook causes offset python,matplotlib,ipython-notebook I have a matplotlib patch that I want to add to two different axis objects. Calling ax1.add_patch(my_patch) the first time leads to the correct result, but when I call ax2.add_patch(my_patch), the patch is offset horizontally. Calling add_patch again after that does not change the offset. This only seems to happen... matplotlib - what kind of set_major_locator should I use python,matplotlib I have a question regarding a plot feature when the X-Axis is a date. Setting I have a two time-series dt and x, where dt is a list of datetime.datetime values and x is a numpy array object. dt = [datetime.datetime(1996, 12, 3, 0, 0), datetime.datetime(1996, 12, 4, 0, 0),... Python - add colorbars in multiple plots for each plot python,matplotlib,colorbox,subplot I have multiple plots on a figure. I would like to add colorbars for each results. These colorbars must have the same height of my results and i would like to limit the numbers displayed on the colorbar to 3 values (in order to have readable figures). My code is... Python anotation arrow direction python,python-2.7,matplotlib,annotations I am trying to annotate a scatter plot in Python 2.7, with Matplotlib. Here is the plot code: import pandas as pd import numpy as np import matplotlib.pyplot as plt df = pd.DataFrame(np.random.rand(5,3), columns=list('ABC')) df.insert(0,'Annotation_Text',['ABC','DEF','GHI','JKL','mnop']) q = 2 pqr = 1 # Scatter Plot: x = df['A'] y = df.iloc[:,q]... Why is the output of my function in binary? python,numpy,matplotlib I wrote a differentiable Heaviside function and vectorised it. However, the output seems to be odd and binary. The code is as follows: import numpy as np import matplotlib.pyplot as plt def heaviside(x, epis): if (x>= epis): y=1 elif (x< -epis): y=0; else: y = 0.5 + x/(2*epis) + np.sin(np.pi*x/epis)/(2*np.pi);... How to add legends and title to grouped histograms generated by Pandas pandas,matplotlib I am trying to plot a histogram of multiple attributes grouped by another attributes, all of them in a dataframe. with the help of this question, I am able to set title for the plot. Is there an easy way to switch on legend for each subplot. Here is my... Matplotlib: How to force integer tick labels? python,matplotlib,plot My python script uses matplotlib to plot a 2D "heat map" of an x, y, z dataset. My x- and y-values represent amino acid residues in a protein and can therefore only be integers. When I zoom into the plot, it looks like this: As I said, float values on... Make a heatmap with a specified discrete color mapping with matplotlib in python python,matplotlib I would like to make a heatmap for a matrix of data such that all positions that are 1 will be red, all positions that are 2 will be white, and etc. with an arbitrary specification. Ideally this should handle the case where all of the values are the same,... Solving nonlinear differential first order equations using Python python,math,numpy,matplotlib,scipy I would like to solve a nonlinear first order differential equation using Python. For instance, df/dt = f**4 I wrote the following program, but I have an issue with matplotlib, so I don't know if the method I used with scipy is correct. from scipy.integrate import odeint import numpy as... Matplotlib/Genfromtxt: Multiple plots against time, skipping missing data points, from .csv python,csv,matplotlib,plot,genfromtxt I've been able to import and plot multiple columns of data against the same x axis (time) with legends, from csv files using genfromtxt as shown in this link: Matplotlib: Import and plot multiple time series with legends direct from .csv The above simple example works fine if all cells... How to label and change the scale of Seaborn kdeplot's axes python,matplotlib,seaborn Here's my code import numpy as np from numpy.random import randn import pandas as pd from scipy import stats import matplotlib as mpl import matplotlib.pyplot as plt import seaborn as sns fig = sns.kdeplot(treze, shade=True, color=c1,cut =0, clip=(0,2000)) fig = sns.kdeplot(cjjardim, shade=True, color=c2,cut =0, clip=(0,2000)) fig.figure.suptitle("Plot", fontsize = 24) plt.xlabel('Purchase... Python - Label size of colorbar python,matplotlib,colorbar I would like to reduce the size of my labels of different colorbars. Currently i got picture you can see below. I try a "labelsize" in plt.colorbar but it doesnt work My code is : plt.close() fig, axes = plt.subplots(nrows=1, ncols=3) plt.tight_layout(pad=0.05, w_pad=0.001, h_pad=2.0) ax1 = plt.subplot(131) # creates first... Plotting ordinal data with a marker in matplotlib python,matplotlib I have some data for which I have experimental and simulated values, the data isn't really continuous without introducing a new definition (which I don't want to do) so I wish to display it ordinally in a scatter type plot with two markers for each set and then label each... A right way to represent 4 dimension points using colors in a matplotlib scatter python,matplotlib I'm currently trying to represent a set of 4 dimensional points in a 3D space using a matplotlib scatter. For do that, I represent the 4th dimension as the color of the 3D point. According to that, I want to print colored points. Therefore, the color of this points depends... Python - Overlap of figures with matplotlib python,matplotlib,subplot I have plot subplots in matplolib, but i have some overlaps and i cant correct it as you can see below : I try with that, but, i cant move each plots...an other way could be to remove the number "pixels" of the grid (not plt.axis(off)! i would like to... Writing pandas/matplotlib image directly into XLSX file python,excel,pandas,matplotlib,xlsxwriter I am generating plots in pandas/matplotlib and wish to write them to an XLSX file. I am not looking to create native Excel charts; I am merely writing the plots as non-interactive images. I am using the XlsxWriter library/engine. The closest solution I have found is the answer to this... Data Analysis and Scatter Plot different file and different column python,data,matplotlib,analysis i have a lot of files and i want to open, read data1.txt and data2.txt file and then data1.txt file 22. column "x_coordinate" and data2.txt file 23. column "y_coordinate" scatter plot. how can i ? with open('data1.txt') as f: with open('data2.txt') as f2: data1 = f.readlines() data2 = f2.readlines() f1.xArr=[]... Python - Superimpose 2 plots in subplot with matplotlib by using alpha channel python,matplotlib,plot,alpha I would like to superimpose 2 plots in one plot by using "alpha channel". I try to get the contour of the right figure on plot of left: My code is : plt.close() fig, axes = plt.subplots(nrows=1, ncols=3) plt.tight_layout(pad=0.05, w_pad=0.001, h_pad=2.0) ax1 = plt.subplot(131) # creates first axis ax1.set_xticks([0,2000,500,1000,1500]) ax1.set_yticks([0,2000,500,1000,1500])... Renaming the x-axis values in matplotlib python-2.7,csv,matplotlib,graphing NOTE: This is all done on a windows 7 x64bit machine running python2.7 and the most recent version of matplotlib. I have a csv file that contains the liquor sales in Iowa from January 2014 to February 2015. If your interest is suddenly piqued, the file can be found at:... Rebin data and update imshow plot python,numpy,matplotlib,draw,imshow I have a large data set I want to be able to "zoom" in on. What I really want is for the data to be rebinned based on the selection and then update the data in the graph. So the graph will show different limits but maintain the same resolution.... How to update quiver plot after moving object on it? python,python-3.x,matplotlib I'm writing small visualization project which suppose to show vector field around few charged bodies. My problem is next: I don't know how to update quiver field after moving circle (charged particle) from primary position. Link to image, because my reputation is too low. I'm practically new with stackoverflow. from... standard form matplotlib — change e to \times 10 python,matplotlib In matplotlib, the axes are sometimes displayed in standard form. The numbers are shown by the ticks and something like '1e-7' appears by the axis. Is there a way to change that to a written out$\times 10^{-7}$? I am not looking to change the labels on each individual tick.... python matplotlib invisible point python,matplotlib I am learning matplolib. I try do display specific point on a surface and I get the following result : Both screenshot comes from the same figure. On the first one, we can hardly see the point I want to display, not on the second. I would like to make... numpy.where() on grayscale frame, wrong indices? python,opencv,numpy,matplotlib,ransac I'm trying to implement a basic RANSAC algorithm for the detection of a circle in a grayscale image. The problem is that, after I thresholded the image and I search for non-zero pixels I get the right shape, but the points are somehow delocalized from the original position: video =... Python: matplotlib - probability mass function as histogram python,python-2.7,matplotlib,plot,histogram I want to draw a histogram and a line plot at the same graph. However, to do that I need to have my histogram as a probability mass function, so I want to have on the y-axis a probability values. However, I don't know how to do that, because using... How to surround curves with annotation in matplotlib? python,matplotlib I have a python code that produces the following figures. I would like to do an annotation with ellipses to surround the curves as the figure mentions. N.B. The figure is produced using MATLAB and I cannot do it in python-matplotlib. Thanks.... matplotlib scatterplot: adding 4th dimension by the marker shape python,matplotlib I would like to add a fourth dimension to the scatter plot by defining the ellipticity of the markers depending on a variable. Is that possible somehow ? EDIT: I would like to avoid a 3D-plot. In my opinion these plots are usually not very informative.... Pandas/Matplotlib histogram issues - x-axis ticks disappearing w subplots and extra unneeded chart space. Tried tight_layout and subplots_adjust python,pandas,matplotlib,histogram having a couple issues plotting Histogram subplots in Matplotlib (this seems Histogram specific.. the same with bars and line graphs seem don't seem to have this issue): I can't get the x-axis tick labels to show up on my top 2 charts. In my code below, I haven't once specified... how seaborn changes the behavior of pyplot by just importing the package? python,matplotlib,monkeypatching,seaborn I am very curious to know how seaborn changes the behavior of matplotlib functions by just import seaborn as sns. I want to realize the same function to change the behavior of imshow() function in pyplot, for example, i want to show the pixel value at the figure's low left... Matplotlib Legend Guide basic examples python,matplotlib I am trying to understand how to use the legend() better, specifically how to use proxy artists. I find the Legend guide to be severely lacking. This post is somewhat similar to this one. I am using Python 2.7.5 on Windows 7, matplotlib version 1.2.1. I wrote this code which... Matplotlib Line2D unexpected behavior python,matplotlib,plot This is a minimum working example. I expect the following code to draw a line from (-2.33,10) to (4.33,-10), but the line I get is totally different. What is wrong? import matplotlib.pyplot as plt import matplotlib fig = plt.figure() ax = fig.add_subplot(111) ax.axis((-10,10,-10,10)) line = matplotlib.lines.Line2D((-2.33,10.0),(4.33,-10.0)) ax.add_line(line) plt.show() ... How can I change the color of a grouped bar plot in Pandas? python,pandas,matplotlib I have this plot that you'll agree is not very pretty. Other plots I made so far had some color and grouping to them out of the box. I tried manually setting the color, but it stays black. What am I doing wrong? Ideally it'd also cluster the same tags... Plotting non-numeric x-axis away from the y-axis python,matplotlib I am using matplotlib to graph a curve with a non-numeric x-axis. I would like there to be some space between the y-axis and the start of the plot. This code implements a subplot with a gap (on the left) & a subplot with a gap using the set_xlim method... How can I customize the offset in matplotlib python-3.x,matplotlib I would like to customize the offset use in matplotlib. Specifically: Set the limits when used (similar to power limits for scientific notation) Customize the format string on both the axis ticks. Doing so with ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%.1f')) switches the scientific notation off. Thank you for the answer, in case somebody encounters... Plot only one or few rows of a correlation matrix python,numpy,matplotlib,heatmap,correlation I have a correlation matrix named corrdata that I calculated using numpy.corrcoef. Then what I do is extract one or a few rows of this matrix, and now just want to plot them instead of the whole matrix. Because the matrix is no longer square, it is not possible to... Why is my plt.savefig is not working? python,numpy,matplotlib I have a simple python code as follows: import numpy as np import matplotlib.pyplot as plt """ Here are the solutions and the plot. """ # Create the axis and plot. plt.axis([0, 10, 0, 10]) axis_x = range(1, 11) grd = [1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1,... Creating plots from 2-D values generated in a for loop in Python python,for-loop,matplotlib,plot I'm creating a trail of the (x,y) co-ordinates generated in a for-loop. But the plot pops up and it's blank. Can someone help the noob out? import random import math import matplotlib.pyplot as pl x = 0 y = 0 dx = 0 dy = 0 v = 2 n=100... Read One Input File and plot multiple python,numpy,matplotlib,graph,plot I am trying to read one input file of below format. Where Col[1] is x axis and Col[2] is y axis and col[3] is some name. I need to plot multiple line graphs for separate names of col[3]. Eg: Name sd with x,y values will have one line graph and... Adding multiple labels at once for matplotlib subplots from pandas dataframe python,pandas,matplotlib I am getting lost here, maybe confusing matplotlib and pandas functionality. I have a dataframe that I want to plot in several subplots to group related data. Everything works as intended, but I cannot get the legend working (which is ridiculously simple if I do not use the subplots). Here... Plotting two different arrays of different lengths python,numpy,matplotlib,plot I have two arrays. One is the raw signal of length (1000, ) and the other one is the smooth signal of length (100,). I want to visually represent how the smooth signal represents the raw signal. Since these arrays are of different length, I am not able to plot... How to add plot labels of different axes to the same legend in Python? python,matplotlib,plot,axes I am trying to plot two curves on two y-axes as shown in figure. The red plot (pressure) the primary axis and green (needle lift) the secondary axis. And I am trying to add the plot labels to the same legend. But I cannot add them to the same legend.... How to build custom pandas.tseries.offsets class? python,pandas,matplotlib,datetimeoffset I want to find a way to build a custom pandas.tseries.offsets class at 1 second frequency for trading hours. The main requirement here is that the time offset object would be smart enough to know the next second of '2015-06-18 16:00:00' would be '2015-06-19 09:30:00 or 09:30:01', and the time... Subplots in matplotlib creating a loop python,loops,matplotlib,subplot I'm new to python and I am trying to create a series of subplots with the only parameter changing being the fill_between parameter for each plot. Currently I repeat the whole code and change the fill_between for each subplot. Is there a more efficient way of creating a loop for... Matplotlib Margins when plotting with Pandas python,pandas,matplotlib I'm trying to set margins so all my points are visible when plotting with matplotlib but its doesn't seem to correctly add them. Below is my code and output. I'm using IPython with the %matplotlib magic command. Is there something that I'm doing obviously wrong? import matplotlib.pyplot as plt import... show matplotlib colorbar instead of legend for multiple plots with gradually changing colors python,matplotlib,data-visualization I am trying to make a simple plot that shows a lot of curves that belong to a large dataset with a certain order, let's say plot 1..n. The shape of the curves changes gradually with increasing n. It is not important that readers can see exactly which plot belongs... Zipping ticklines does not allow to change their properties python,matplotlib,python-3.4 I was trying to reduce my code footprint to make it more readable when I stumbled around an odd result. If I run the following code: y1 = np.linspace(1,1000) y2 = np.linspace(10,1) c = ["b","g"] fig, ax = plt.subplots() ax.plot(y1, c[0]) ax2 = ax.twinx() ax2.plot(y2, c[1]) for tl in ax.yaxis.get_ticklines():... How do I make each histogram bin show me the frequency of each action/event/item? python-3.x,matplotlib,histogram I want to plot a histrogram showing the frequencies of various actions at different intervals. I want to bin the occurence of actions into 10 minute intervals. binwidth = 10*60 #10 minutes times = array([ 1.43431325e+09, 1.43431325e+09, 1.43431329e+09, 1.43431330e+09, 1.43431333e+09, 1.43431334e+09, 1.43431345e+09, 1.43431346e+09, 1.43431346e+09, 1.43431346e+09, 1.43431349e+09, 1.43431350e+09, 1.43431350e+09, 1.43431351e+09, 1.43431354e+09,... Python - Add annotation in subplot imshow python,matplotlib,annotations,imshow I would like to add some annotations on a figure with multiple subplots...On the figure below i would like to write something below the 2 right figures and at the left top. How can i do that? I try with : ax3.text(0.1, 0.5, '$\sigma =\$' resV.mean(), size=12, ha='center', va='center') But...

python,matplotlib,plot,fill
I'm trying to get access to the shaded region of a matplotlib plot, so that I can remove it without doing plt.cla() [since cla() clears the whole axis including axis label too] If I were plotting I line, I could do: import matplotlib.pyplot as plt ax = plt.gca() ax.plot(x,y) ax.set_xlabel('My...

changes axis of scatter plot with slider matplotlib python

python,matplotlib,widget,scatter-plot
I have a very large data set and want the user to be able to slide along the axis to view sections of the data. I'm trying to leverage off of the slider example but I'm unsure of how to update the graph. Hoping someone can explain some of the...

Change plot label when plotting different dataframes in pandas

python,pandas,matplotlib
I aggregated on pivot tables some time series information, so each pivot table have columns labeled 2015, 2014, etc. I want to compare each pivot table, so I'm plotting them on the same axis: print pv_test_A.columns Int64Index([2010, 2011, 2012, 2013, 2014, 2015], dtype='int64') print pv_test_B.columns Int64Index([2010, 2011, 2012, 2013, 2014,...

matplotlib animation.save to animated gif very slow

python,matplotlib,imagemagick,animated-gif
I'm animating a convergence process that I'm simulating in an IPython 3.1 notebook. I'm visualizing the scatter plot result in a matplotlib animation, which I'm writing out to an animated gif via ImageMagick. There are 3000 frames, each with about 5000 points. I'm not sure exactly how matplotlib creates these...

Matplotlib: Plot the result of an SQL query

python,sql,matplotlib,plot
from sqlalchemy import create_engine import _mssql from matplotlib import pyplot as plt engine = create_engine('mssql+pymssql://**:****@127.0.0.1:1433/AffectV_Test') connection = engine.connect() result = connection.execute('SELECT Campaign_id, SUM(Count) AS Total_Count FROM Impressions GROUP BY Campaign_id') for row in result: print row connection.close() The above code generates an array: (54ca686d0189607081dbda85', 4174469) (551c21150189601fb08b6b64', 182) (552391ee0189601fb08b6b73', 237304) (5469f3ec0189606b1b25bcc0',...

Matplotlib axis tick format changes after zoom in ipython figure window

python,matplotlib
In ipython figure windows, I have observed the following feature that I would like to turn off: Here's a plot I made using the pyplot.errorbar() inside of an ipython terminal. In this figure, the horizontal axis tick label format is behaving the way I would like it to: However, upon...

Fill between y = 0 and positive values of y

python,python-3.x,matplotlib
I'm practicing the fill_between matplotlib function. What I want to do is to fill the area between y = 0 and the positive values of y and let the area between y = 0 and the negative values of y unfilled. Something like: import matplotlib.pyplot as plt x = [1,2,3,4,5]...

Python (Matplotlib) - Tick marks on ternary plot

python,python-2.7,matplotlib
I am trying to draw tines that look like tick-marks on the sides of an equilateral triangle. I am doing this using Matplotlib in Python. Here is the equilateral triangle***: import matplotlib.pyplot as plt from pylab import * fig = figure() ax = fig.add_subplot(111) ax.axis('equal') ax.plot([1, 0.5], [0, 0.866], 'k-')...

Interactive pcolor in python

python-2.7,matplotlib,plot,interactive
I have two numpy arrays of sizes (Number_of_time_steps, N1, N2). Each one represents velocities in a plane of size N1xN2 for Number_of_time_steps which is 12,000 in my case. These two arrays come from two fluid dynamics simulations in which a point is slightly perturbed at time 0 and I want...

matplotlib mean interval plot

python,pandas,matplotlib,plot
I'm transitioning from R to python, and was looking to plot the mean line of a two variables. It is the plot of the x variable is split into intervals for the x axis, and mean of the y variable for the y axis. For example, if I have 1000...

Hierarchy in matplotlib

python,matplotlib,plot
According to this article, everything in matplotlib is organized in a hierarchy. At the top of the hierarchy is the matplotlib "state-machine environment" which is provided by the matplotlib.pyplot module. At this level, simple functions are used to add plot elements (lines, images, text, etc.) to the current axes in...

Python plot Legend Key Format

python,matplotlib
I am trying to plot a set of data in python. I'm using matplotlib.pyplot library to do this. I got everything working, but I have this one issue where the last key in the legend comes out with a weird format than the others. I tried to do different settings...

Declaration of FigureCanvasTkAgg causes memory leak

python,python-2.7,matplotlib,memory-leaks,tkinter
I'm having difficulty figuring out just why the declaration of FigureCanvasTkAgg causes a memory leak, I have the following lines in my class __init__ method: # pndwinBottom is a paned window of the main screen self.__drawplotFrame = Frame(pndwinBottom, width=WIDTH, height=HEIGHT) # the frame on which we will add our canvas...

Adding colorbar to a 3 variable colour graph

python,matplotlib
From another post I got how to create the graph, but am struggling to add a scale bar. Printing an item from colors gives [ 0.53800422 0.67490159 0.99172189 1.] which i'm guessing is the scaled color? my_array = range(20) my_array2 = my_array z = np.array(my_array) x = np.asarray(my_array) scaled_x =...