I've been working with Sympy for an Interpolation, in wich I obtain as a result a 7th degree Polynomial (ax^7 + bx^6 + cx^5 + ...+ h) wich I want to Plot, but wen I try to plot it I get errors, for example, if i try:

```
plt.plot(r,U.subs(x,r))
```

where `r = np.linspace(0,20,num=100)`

and `U = Polynomial(x)`

; the result is an error message: `ValueError: sequence too large; must be smaller than 32`

, I obtain `MemoryError:`

if I try `r = np.arange(20)'. The only way I could plot it is with a for cycle, subtituing one by one and saving it in another variable as a list. So my question is, what is wrong with the first's inputs? is there an easy way to plot a polynomial?

Answer:

Welcome to SO!

The `subs()`

method is not meant to be used with numpy arrays. lambdify() does what you want. Try:

```
import numpy as np
import matplotlib.pyplot as plt
import sympy as sy
sy.init_printing() # nice formula rendering in IPython
x = sy.symbols("x", real=True)
# the sample polynomial:
pp = x**3 + 3*x**2 - 6*x - 8
# Convert expression function usable with numpy array:
f_pp = sy.lambdify(x, pp, modules=np)
# Do the plotting:
x_n = np.linspace(-5, 2, 500)
y_n = f_pp(x_n) # evaluate all x_n
fg, ax = plt.subplots(1, 1)
ax.plot(x_n, y_n)
fg.canvas.draw()
plt.show()
```

The parameter `modules=np`

ensures, that numpy is used for functions in the expression (e.g., `sin()`

=> `np.sin()`

). In this example, it is not explicitly needed.

PS: If you include a runnable example in your question, it makes live much easier for potential answerers.

plot,gnuplot

I have a file with 1600 columns. plot "file" using 1:999 title columnhead(999) plots column 999, but plot "file" using 1:1000 title columnhead(1000) produces column 100 instead of 1000, producing the same result as plot "file" using 1:100 title columnhead(100) Apparently large column numbers are wrapped. Is there a work-around...

python,ipython,ipython-notebook

Related posts: Open an ipython notebook via double-click on osx How can I open Ipython notebook from double click? I always cd to the directory of the notebook, then type ipython notebook in the browser and then open it in the browser. This steps is very inconvenient. In windows, I...

matlab,image-processing,plot,3d,surface

Refer to the attached image. I want to display the image in Matlab using the function surf(). However, I only want to display the region of the actual object without the background (the pale-green region surrounding the actual object which has 0 value). How to do that? I tried replacing...

javascript,jquery,plot,flot

I am working on an application where I am trying to plot a similar graph to what is plotted at Open Weather. I am using the FlotJS library to query their API and plot the graphs. Here is my code. I apologize for the verbosity. /* * RUN PAGE GRAPHS...

javascript,plot,highcharts

I have a Highcharts column plot that shows four series. I would like series one and two to be touching each another (the two blue ones), then have a small gap, and then have series three and four touching each another (the orange ones). Can this be done? I haven't...

r,plot,ggplot2,facet

I am trying to set the labels on a categorical axis within a faceted plot using the ggplot2 package (1.0.1) in R (3.1.1) with scales="free". If I plot without manually setting the axis tick labels they appear correctly (first plot), but when I try to set the labels (second plot)...

python,csv,pandas,plot

I'm trying to read following csv-file with panda and plot a column of it: data type,approved mining area,mined area,coal content,earth rate,coal rate,waste ratio unit,ha,ha,Mt,Mm3/a,Mt/a, Garzweiler,11400,3096,1246,140,37.5,4.4 Hambach,8500,4224,1500,275,40,5.2 Inden,4500,1655,358,87.5,22.5,3.6 which gives me the following (only a part so it fits here): data type approved mining area mined area coal content earth rate...

matlab,plot,line

I'm trying to plot a line graph and a bar graph on the same y-axis: figure; plotyy(Pert, Rfootvel(:,i+1), Pert, 0,'bar','plot'); hold(ax(1), 'on'); legend('Pert 1-8', 'Base'); ylim(ax(2), [0 1]); title(['The avg pert velocity of the first step vs the avg base velocity, PP' num2str(j)]); Unfortunately, setting the second y-axis limit like...

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

plot,sas

I am trying to plot two sets of line graphs on the same chart: /* make data */ data test ; do i = 1 to 2 ; do x = 1 to 5 ; y = i*x ; z = 0.5*i*x ; output; end ; end ; run ;...

javascript,google-maps,plot

I am writing a simple application to plot multiple marker in the google map and connect it thought a path as it looks like a route . I can plot multiple marker . and search some article which plot the route map . but i can not plot it ....

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

r,plot,time-series,kriging

Let's say I have the output of a monte-carlo simulation of one variable over several different iterations (think millions). For each iteration, I have the values of the variable at each point in time (ranging from t=1 to t=365). I would like to produce the following plot: For each point...

r,plot

I'm researcher and not a programmer. I have often used the drc package, to analyze data. There you can define a curveid and it will plot multiple lines in one plot. I need the same thing just for the normal plot, but obviously is my knowledge to little to do...

plot,stata

I'm working with the ciplot graphing module for Stata and am encountering a problem with the alignment of bars when I use the by() option. Here's a trivial example demonstrating the issue: webuse citytemp, clear ciplot heatdd cooldd, by(region) horizontal recast(conn) So, the graph shows means and confidence intervals for...

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

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

r,plot,sp

I'm trying to plot a SpatialPoints object using the generic function from the Package graphics. The extent of the plot should be exactly the size of the outermost datapoints. Here's a simple example where the ratio of delta x over delta y (outermost values) is 1: library(sp) xydata <- as.matrix(cbind(c(1,1,2,2,1.5),c(1,2,2,1,1.5)))...

matlab,plot

I want to display three figures in a figure window. Assuming that I divide 2x2 regions. subplot(2,2,1) ---------+----------- | R1 | R2 | ---------+----------- | R3 | R4 | ---------+----------- I want to show a figure merging R1 and R3 ant other two in R2 and R4 I can display...

ipython,ipython-notebook,jupyter

I am trying to run ipython 2.7 notebooks with jupyterhub on Ubuntu 14.04 - but I haven't been able to figure out a way. Any suggestions? I know one needs to add kernels in the file ~/.ipython/kernels.json I have the following in this file: { "argv": ["python3", "-m", "IPython.kernel", "-f",...

r,plot,ggplot2,cdf

Currently I am doing some cumulative distribution plot using R and I tried to set x-axis with decreasing power values (such as 10000,1000,100,10,1) in equal sizes but I failed: n<-ceiling(max(test)) qplot(1:n, ecdf(test)(1:n), geom="point",xlab="check-ins", ylab="Pr(X>=x)")+ geom_step() +scale_x_reverse(breaks=c(10000,1000,100,10,1)) +scale_shape_manual(values=c(15,19)) It seems that the output has large interval for 10000, then all the...

matlab,plot,bar-chart

I am try to plot 16 bars, 8 of these belong to one group. I want to give this group the red color, the other 8 belong to another group which is given the blue color. I would like to arrange the bar in pairs, each pair containing one from...

python,matplotlib,plot,google-visualization,heatmap

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

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?

r,plot,shiny,rcharts

I am using following simple shiny app code snippet to plot the output in the main pannel. But it doesn't render the plot as expected. It shows nothing in the browser. But When i run only the mPlot portion, it displays the plot in RStudio correctly with all interactions. ui.R...

matlab,plot,legend,movie

i have a question regarding legend for movies. This is my code: fig = figure(); for i = 1: 70000 plot(signal1) hold on; plot([i,i],[-5,5]) plot(signal2,'r') hold off; title('\fontsize{14} my data'); legend('signal1','signal2'); axis tight; f(i) = getframe(fig); end The legend shows the same colors for the first two things I plot....

r,plot,ggplot2

I have a shapefile, specifically, a SpatialPolygonsDataFrame, called cdtract. that contains one variable for each district called varcount. varcount is either "NA" or 1. When I do plot(cdtract) ...I see the map printed out but I don't see the tracts that are '1' in varcount marked any differently from those...

python,shell,profiling,ipython,ipython-magic

I am trying to do file profiling in IPython, generate some profiling stats output and then pass it to some Python profiling GUI tools like KCachegrind. Here is my code trying to do that. All codes are executed in IPython. # example function for profiling def factorial(n): if n ==...

plot,gnuplot,highlight

I have 4 points I would like to plot using gnuplot, but with lines. The problem is, I can't find how to highlight these 4 points on the drawn line. I would like for the plot to be a line through the points, but that these points are also clearly...

r,plot

I have 4 regression lines and I want to have them in one plot. Here is my simple code: data = read.csv("TEST.csv", header = FALSE) plot(data$V1,data$V2) fit <- lm(data$V2~data$V1) abline(fit, col=1) data1 = read.csv("TEST1.csv", header = FALSE) fit1 <- lm(data1$V2~data1$V1) abline(fit1, col=2) data2 = read.csv("TEST2.csv", header = FALSE) fit2 <-...

matlab,plot

I have multiple 2D line plots in Matlab (they represent some wave moving through space). Each plot represents the wave at some time t. I want to animate through these plots (i.e. show the first plot for a fraction of a second, then show the next one, and the next,...

matlab,graphics,plot,matlab-figure

I have a MATLAB code as follows: MinVal = -1; MaxVal = 1; MaxRadius = 0.5; nCircles = 5; Dimension = 2; Circles = zeros(nCircles, Dimension); Radius = zeros(nCircles, 1); for i = 1 : nCircles Circles(i,:) = unifrnd(MinVal, MaxVal, [1, Dimension]); Radius(i) = unifrnd(0, MaxRadius, 1); end t =...

linux,graph,plot,gnuplot

Im plotting one picture with 4 different graphs using gnuplot. Labels for their x and y axes have the same meaning. If Im plotting it like this: set multiplot layout 2,2 rowsfirst set xlabel "x" set ylabel "y" set title offset -3,-3 set xrange [20:70] set yrange [0:15000] set title...

matlab,plot,axis,shift

I cannot get Matlab to plot a a second time series to specific points along the x axis. My data are two time series. Time series A is a 5 X 1 and time series B is a 7 X 1. I need A to plot on xticklabels 1-5. Then,...

python,ipython,magic-function

Is there some way I can use %run to execute a subset of a file? Something like this: $ ipython In [1]: %run my_code.py -L 20 100 # executes lines 20-100 in ipython interpereter ...

r,plot,histogram

Given this example of back to back histogram: set.seed (123) xvar <- round (rnorm (100, 54, 10), 0) xyvar <- round (rnorm (100, 54, 10), 0) myd <- data.frame (xvar, xyvar) valut <- as.numeric (cut(c(myd$xvar,myd$xyvar), 12)) myd$xwt <- valut[1:100] myd$xywt <- valut[101:200] xy.pop <- data.frame (table (myd$xywt)) xx.pop <- data.frame...

matlab,plot

I have a semilogarithmic plot which works so far with semilogx. Now I would like to change the tick labels. Now it says 10^8 10^9 ... 10^13, but I would like to see 1e8, 1e9, ... 1e13 on the x-axis. How can I change that? Cheers Manuel...

python,vector,ipython,linear-algebra,ipython-notebook

Hi I'm following "Data Science from Scratch" and I got an error when I was making vector sum function. Could someone help? The code: a = [1,2,3] b = [2,3,4] def vector_add(v, w): """adds two vectors componentwise""" return [v_i + w_i for v_i, w_i in zip(v,w)] vector_add(a,b) #prints [3, 5,...

r,plot,rotation,raster

I have code below which saves an image to my pc. I would like to rotate that image by 45,90 and 135 degrees around its center (or bottom left hand corner) and then save as 3 different images. How could I do that? library(raster) r1 <- brick(system.file("external/rlogo.grd", package="raster")) x <-...

matlab,plot,matlab-figure

I am going to draw a figure such as below picture in the MATLAB R2014b: . This figure consists of many circles with different (random) colors and random sizes. How is it possible to plot such this figure in MATLAB R2014b?...

plot,shiny,reactive-programming,weight

I am filtering a tbale and a heat-map simultaneously. During filtering, the width of the table is changing such that width of particular columns remains the same. Width of the heat-map remains the same during filtering. I want the heat-map to change its weight in the same way as the...

r,plot,lattice

I plotted a histogram using Lattice histogram(~Time |factor(Bila), data=flexi2, xlim= c(5, 15), ylim=c(0, 57), scales=list(x=list(at=seq(5,15,1))), xlab="Time", subset=(Bila%in% c(""))) The bins I get do not match the exact hours, whereas I would like the bin to start at the exact hour, for example, 6,7 etc. I use lattice since I want...

r,plot,ggplot2

I have problems using annotation_custom. Here is the dataset: DOSE PROD pH 1 0 CL 4.3550 2 0 CO 4.3250 3 0 CZ 4.1475 4 0 PF 4.2300 5 0 RP 4.1225 6 25 CL 4.3420 7 25 CO 4.3520 8 25 CZ 4.7840 9 25 PF 4.2640 10 25...

python,sql,matplotlib,plot

from sqlalchemy import create_engine import _mssql from matplotlib import pyplot as plt engine = create_engine('mssql+pymssql://**:[email protected]: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',...

matlab,image-processing,plot,histogram

I have calculated 3 histograms for an rgb image using imhist function in Matlab, one for each channel. I want to plot these histograms on the same graph, where for instance, the histogram for the first (red) channel stretches on the x axis from 0 to 255, the histogram for...

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

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

matlab,plot,signals,circle

I have some random signal (for example sin signal) with the time scale. t=0:0.1:2*pi y=sin(t) plot(t,y) Now I want to draw this signal on this circle. So the time vector actually becomes an envelope of the circle. Envelope of the circle represents "y = 0" in cartesian coordinate system. Here...

javascript,r,plot,statistics,shiny

I'm working on a project to build several models for data analysis and reporting using R and the amazing Shiny framework for web development. I'm getting started with R and Shiny but I've had an amazing experience so far, yet, I'd like to get some help in case someone has...