Kpb
Kpb

Reputation: 33

I cannot figure out how to spread out the space on the y axis for my scatterplot in Python

I entered this code with the x, y, and size defined by variables I created earlier. The problem is that the points are too bunched up and I want to stretch out my y-axis.

plt.scatter(rets.mean(),rets.std(),s = area)
plt.xlabel('Expected Return')
plt.ylabel('Risk')

For example, right now my y-axis goes from -0.005 to 0.04 in increments of 0.005, how would I adjust it to count in increments of 0.0025?

Upvotes: 2

Views: 1974

Answers (1)

tacaswell
tacaswell

Reputation: 87376

import matplotlib.pyplot as plt
import matplotlib.ticker as mticks

fig, ax = plt.subplots()

ax.set_ylim((-.005, .04))
ax.yaxis.set_major_locator(mticks.MultipleLocator(.0025))

enter image description here

Upvotes: 4

Related Questions