I am creating a 2 axis line chart with Matplotlib. There are multiple data series in the chart. I have the y axis set to log scale because the 2 series have different ranges.
import pandas as pd
import matplotlib.pyplot as plt
data = {
'Sales':[ 1141, 1356, 1604, 2165, 2494, 2933, 3445, 4198, 4287, 4760],
'Profit': [10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ],
'Year':['2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019']
}
df = pd.DataFrame(data, columns = ['Sales', 'Profit', 'Year'])
# multiple line plot
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.set_yticklabels(df.Profit)
plt.plot( 'Year','Sales', data=df, marker='o', color='brown', linewidth=1)
plt.plot( 'Year','Profit', data=df, marker='o', color='green', linewidth=1, linestyle='dashed')
plt.legend()
plt.yscale("log")
plt.draw()
The output chart is shown with very less y axis labels. Is there a way to display all the y -axis values' labels in the cart? Or is there a way to show y-axis labels at a higher frequency, to make reading the values easier?
I have tried this related solution How to display all label values in matplotlib? but it did not show all the y labels.
I have also tried to set explicit y tick values, like this, but still the labels did not show up.
ax1 = fig.add_subplot(111)
ax1.set_yticklabels(np.arange(5000), minor=True)