Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8691929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:13:16+00:00 2026-06-13T00:13:16+00:00

I am trying to plot a line in matplotlib.. I am searching for the

  • 0

I am trying to plot a line in matplotlib.. I am searching for the right type of interpolation.. I want something like this

taken from canvasxpress.org/line.html

where every line is smoothed. I tried several combination of scipy and matplotlib, such as

x_new = np.arange(x, x_length, 1)
tck = interpolate.splrep(x, y, s=3)
y_new = interpolate.splev(x_new, tck, der=0)
ax.plot(x_new, y_new, color+lstyle)

but the best result I get is

my result

The line represents an increasing variable.. so it is a wrong representation. What can I search for?

Thanks

Edit: I am thinking about implementing a method from myself, but I don’t know if it has been already done.. pseudo code is the following

take x and y
calculate spline for each three points 
x[0], x[1], x[2] ... x[1], x[2], x[3] ... and so on
for each y[n] sums every computation done for it and divide by number of 
computations (i.e. y[1] is computed for triplette x[0..2] and x[1..3] so the 
sum is divided by two (average for each point is taken as its value)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:13:18+00:00Added an answer on June 13, 2026 at 12:13 am

    For that type of graph, you want monotonic interpolation. The PchipInterpolator class (which you can refer to by its shorter alias pchip) in scipy.interpolate can be used:

    import numpy as np
    from scipy.interpolate import pchip
    import matplotlib.pyplot as plt
    
    
    # Data to be interpolated.
    x = np.arange(10.0)
    y = np.array([5.0, 10.0, 20.0, 15.0, 13.0, 22.0, 20.0, 15.0, 12.0, 16.0])
    
    # Create the interpolator.
    interp = pchip(x, y)
    
    # Dense x for the smooth curve.
    xx = np.linspace(0, 9.0, 101)
    
    # Plot it all.
    plt.plot(xx, interp(xx))
    plt.plot(x, y, 'bo')
    plt.ylim(0, 25)
    plt.grid(True)
    plt.show()
    

    Result:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this horrible massive error when trying to plot using matplotlib: Traceback (most
I'm trying to plot a histogram with matplotlib. I need to convert my one-line
I am trying to plot different types of plots (line plot and bar charts)
I am trying to plot a linear regression line on a scatter plot. I
I'm trying to plot an exponential decay line (with error bars) onto a scatterplot
I am trying to plot this kind of behaviour of a data set. I
I am trying to plot a variable number of lines in matplotlib where the
Trying to plot a signal function of 0 and 1, much like the solution
I'm trying to add vertical lines to a matplotlib plot dynmically when a user
I am trying to run demo code from Matplotlib: the legend_picking example . This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.