0

I just started with python yesterday, since it seemed to be a good and easy solution for our task. We are making a logger which will monitor long-time-tests of batterychargers and other equipment in that field.

Right now I'm using mock numbers made from a number generator, we will soon have some actual and more even numbers to work with, but the actual grap worries me, since it's so compressed. Is there any way to "widen" the x-axis, to up the resolution and thereby stretch the graph?

import numpy  as np 
import matplotlib.pyplot as plt
    
data = np.loadtxt('test.txt')

x = data[:, 0]
y = data[:, 1]
y2 = data[:, 2]
y3 = data[:, 3]

fig = plt.figure(facecolor = ("Pink"))

ax = fig.add_subplot(111)

ax.plot(x, y, '--', label='Voltage')
ax.plot(x, y2, '-.', label='Current')

ax2 = ax.twinx()
ax2.plot(x, y3,'g:', label='Temperature')

fig.legend(edgecolor = ("DarkBlue"), facecolor = ("LightBlue"), loc="upper right", bbox_to_anchor=(1,1), bbox_transform=ax.transAxes)

ax.set_title("Test Surveillance", color = ("Purple"))    
ax.set_xlabel('Milliseconds', color = ("LightGreen"))
ax.set_ylabel('Volts and Amps', color = ("DarkGrey"))
ax2.set_ylabel('Celsius', color = ("LightBlue"))

plt.show()

Ignore the color scheme, it's for testing and annoying my friend.

Here's what it looks like.

tmdavison
  • 64,360
  • 12
  • 187
  • 165
Slangfil
  • 23
  • 6
  • I also have a graph that is super compressed and I have to use the zoom tool from the toolbar to zoom in. Then I also found this [SO](https://stackoverflow.com/questions/16705452/matplotlib-forcing-pan-zoom-to-constrain-to-x-axes) which seems to explain how the internals of the matplotlib work. – Jax Teller Nov 10 '20 at 08:36
  • Does [this](https://stackoverflow.com/questions/20398920/physically-stretch-plot-in-horizontal-direction-in-python) answer your question? – OctaveL Nov 10 '20 at 08:39
  • I believe both answered my question, but it's not applicable because I'm a wee bit stupid. Literally the only way to stretch the x-axis is by physically streching it. To stretch the graph I'd need to grab fewer points of reference. Atleast that's what I've come up with. Thanks for the quick responses! – Slangfil Nov 10 '20 at 08:55

0 Answers0