0

I've been trying to plot a graph of Epoch vs Accuracy and val_accuracy from a train log I have generated. Whenever I try to plot it, the y-axis starts from 0.93 rather than it being in 0, 0.1 ,0.2... intervals. I'm new at using matplotlib or any plot function.

Here's the code for it:

import pandas as pd
import matplotlib.pyplot as plt

acc = pd.read_csv("train_log", sep = ',')

acc.plot("epoch", ["accuracy","val_accuracy"])
plt.savefig('acc' , dpi = 300)

I'm open to suggestion in complete different ways to do this. Picture of plot : [1]: https://i.stack.imgur.com/lgg0W.png

r3tr0
  • 5
  • 3
  • Does this answer your question? [setting y-axis limit in matplotlib](https://stackoverflow.com/questions/3777861/setting-y-axis-limit-in-matplotlib) – Zephyr Aug 03 '21 at 06:18

2 Answers2

0

You need to set the lower/bottom limit using ylim(). For details please refer: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.ylim.html

0

This has already been discussed here. There are a couple of different ways you can do this (using plt.ylim() or making a new variable like axes and then axes.set_ylim()), but the easiest is to use the set_ylim function as it gives you heaps of other handles to manipulate the plot. You can also handle the x axis values using the set_xlim function.

You can use the set_ylim([ymin, ymax]) as follows:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0,5)
y = np.arange(5,10)
axes = plt.gca()
axes.plot(x,y)
axes.set_ylim([0,10])

enter image description here

You can use the plt.ylim() like this:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0,5)
y = np.arange(5,10)
plt.plot(x,y)
plt.ylim([0,10])

This will produce the same plot.

Amir Charkhi
  • 768
  • 7
  • 23