Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change axis style python

I'm making a simple plot of an exponentially decaying cos curve in python. The code is below, there's no problem with the code actually running, I was just wondering if there's a way to change the way python displays the graph so rather than being enclosed by the axes like this it has the axes like this. It's not an urgent problem, it's just to make the plot match more closely with other parts of my report.

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
t = np.linspace(0, 4, 10000)
r=1
x = t
y = r * np.exp(-t)*np.cos(10*t)

plt.plot(x,y,'-')
plt.plot(x,np.zeros(10000),'k-')
plt.show()
like image 620
bigbadpiano Avatar asked Apr 16 '26 11:04

bigbadpiano


1 Answers

Take a look at the Axis line style demo from the matplotlib gallery.

Specifically, the lines:

ax = SubplotZero(fig, 111)

...

for direction in ["left", "right", "bottom", "top"]: 
    ax.axis[direction].set_visible(False)
like image 121
Zachary Cross Avatar answered Apr 18 '26 02:04

Zachary Cross



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!