FAQ Database Discussion Community

## 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...

## 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...

## 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 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...

## 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);...

## 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...

## 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...

## 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...

## 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 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...

## 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...

## 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"...

## 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...

## 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...

## 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...

## 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,...

## 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=[]...

## 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...

## 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...

## 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...

## 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,...

## 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,...

## 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...

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?

## 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...

## 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...

## 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...

## 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...

## 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 -...

## 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...

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

python,matplotlib,networkx

## 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():...

## 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...

## 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...

## 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...

## 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 #...

## 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...

## 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...

## 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',...

## 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:...

## 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...

## 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...

## 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...

## 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...