0

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?

enter image description here

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)
6
  • 1
    Not clear: do you want to annotate each point with its value? Commented Oct 8, 2019 at 18:57
  • 1
    Labelling all minor ticks would look like this; are you sure this is what you want? Commented Oct 8, 2019 at 18:57
  • @wwii Yes. It would improve readability if each point had its value shown in the y axis. Commented Oct 8, 2019 at 19:02
  • @ImportanceOfBeingErnest if I cannot show the individual y axis values on the chart, I would show the minor ticks. How can I do that? Commented Oct 8, 2019 at 19:03
  • Possible duplicate of Matplotlib scatter plot with different text at each data point Commented Oct 8, 2019 at 22:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.