I want to plot a graph with one logarithmic axis using matplotlib.

I've been reading the docs, but can't figure out the syntax. I know that it's probably something simple like 'scale=linear' in the plot arguments, but I can't seem to get it right

Sample program:

```import pylab
import matplotlib.pyplot as plt
a = [pow(10, i) for i in range(10)]
fig = plt.figure()
ax = fig.add_subplot(2, 1, 1)

line, = ax.plot(a, color='blue', lw=2)
pylab.show()``` Oct 15, 2018 in Python 284 views

## 1 answer to this question.

You can use the Axes.set_yscale method. That allows you to change the scale after the Axesobject is created. That would also allow you to build a control to let the user pick the scale if you needed to.

The relevant line to add is:

`ax.set_yscale('log')`

You can use 'linear' to switch back to a linear scale. Here's what your code would look like:

```import pylab
import matplotlib.pyplot as plt
a = [pow(10, i) for i in range(10)]
fig = plt.figure()
ax = fig.add_subplot(2, 1, 1)

line, = ax.plot(a, color='blue', lw=2)

ax.set_yscale('log')

pylab.show()``` answered Oct 15, 2018 by
• 7,720 points

## How can I lookup hostname using the IP address with a timeout in Python?

Good question. I actually was stuck with ...READ MORE

## How can I deal with python eggs for multiple platforms in one location?

Try virtualenv : http://pypi.python.org/pypi/virtualenv This helps you create isolated ...READ MORE

## How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

## How can I create a new file in Python?

You can try the below code which ...READ MORE

## how can i randomly select items from a list?

if you google it you can find. ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## how do i use the enumerate function inside a list?

can you give an example using a ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE