Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting Curved Lines in Python

I'd like to plot curved lines of a specific arch like shape, below is how far I've gotten using specific values (these values need to be used) but it plots straight lines.

I'm also having trouble formatting the y axis the way I want. It's a log scale and I'd like it to go up to 1 (like in the ideal plot above). Some help would be great, thanks! =)

like image 357
Johnsonhesp Avatar asked Aug 14 '26 15:08

Johnsonhesp


1 Answers

The reason why your line is not stretching on a log scale plot is because there are no points between the points that are on the top and on the bottom. log plot does not curve the lines, only place the points on a different scale, the line between them are still straight.

To change this, we add more points between dots. and the result will become curved.

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import ScalarFormatter

# Data for plotting
t = [0.0, 62.5, 125.0, 187.5, 250, 312.5, 375, 437.5, 500]
s = [0.1, 0.005, 0.1, 0.005, 0.1, 0.005, 0.1, 0.005, 0.1]

def extendlist(l):
    master = []
    for i in range(len(l)-1):
        x = np.linspace(l[i], l[i+1], 50)
        master.extend(x)
    return master

t = extendlist(t)
s = extendlist(s)

fig, ax = plt.subplots()
ax.semilogy(t, s)

ax.set(xlabel='x axis', ylabel='y axis', title='Stuff')
plt.xlim((0,500))
plt.ylim((0.001, 1))

plt.show()

This will generate what you graphed on paper.

enter image description here

like image 184
Rocky Li Avatar answered Aug 16 '26 04:08

Rocky Li