Skip to content

Instantly share code, notes, and snippets.

@nickumia
Last active August 26, 2023 06:36
Show Gist options
  • Save nickumia/fa5506806313caaf125fac76c79631c8 to your computer and use it in GitHub Desktop.
Save nickumia/fa5506806313caaf125fac76c79631c8 to your computer and use it in GitHub Desktop.
Pyplot lines example
import matplotlib
gui_env = ['Qt4Agg','WXAgg', 'TKAgg','GTKAgg']
for gui in gui_env:
try:
print("testing", gui)
matplotlib.use(gui,warn=False, force=True)
from matplotlib import pyplot as plt
break
except:
continue
print("Using:",matplotlib.get_backend())
import matplotlib.pyplot as plt
import numpy as np
n = 10
for pos in np.linspace(-n, 2*n, 3*n+1):
plt.vlines(pos, 0, n)
plt.hlines(pos, 0, n)
for pos in np.linspace(-n, 2*n, 3*n*10+1):
plt.axline((pos, 0), slope=1, color='k', transform=plt.gca().transAxes)
plt.axline((pos, 0), slope=-1, color='k', transform=plt.gca().transAxes)
plt.ylim([0, n])
plt.xlim([0, n])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment