3

I am using a pyplot to draw loglog graph. Here is the code:

data = [...] # a list of int values
from scipy.stats import itemfreq
tmp = itemfreq(data) # Get the item frequencies
x = tmp[:, 0] # unique values in data
y = tmp[:, 1] # freq

import matplotlib.pyplot as plt
plt.loglog(x, y, basex=2, basey=2)
plt.show()

And I get this image: Loglog plot

But I don't want the data points to be connected by lines which seems very ugly. How can I do this?

1 Answer 1

2

You can give the plt.loglog() function several different keyword arguments which will change the format of your plot, such as linestyle, marker, and their respective colours.

data = [...] # a list of int values
from scipy.stats import itemfreq
tmp = itemfreq(data) # Get the item frequencies
x = tmp[:, 0] # unique values in data
y = tmp[:, 1] # freq

import matplotlib.pyplot as plt
plt.loglog(x, y, basex=2, basey=2, linestyle='None', 
           marker='x', markeredgecolor='red')
plt.show()

Alternatively you can give a string as a third positional argument which can select the formatting in a simpler way, such as plt.loglog(x, y, 'rx') which will give the same formatting as above (no line with red crosses). The format string arguments available can be found here.

Sign up to request clarification or add additional context in comments.

1 Comment

I must say the matplotlib documentation is misleading, which says the 'marker' parameter is unknown...Anyway, thanks!

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.