简体   繁体   English

python:散点图对数刻度

[英]python: scatter plot logarithmic scale

In my code, I take the logarithm of two data series and plot them. 在我的代码中,我采用两个数据系列的对数并绘制它们。 I would like to change each tick value of the x-axis by raising it to the power of e (anti-log of natural logarithm). 我想通过将其提高到e的幂(自然对数的反对数)来改变x轴的每个刻度值。

In other words. 换一种说法。 I want to graph the logarithms of both series but have x-axis in levels. 我想绘制两个系列的对数图,但是在水平上有x轴。

在此输入图像描述

Here is the code that I'm using. 这是我正在使用的代码。

from pylab import scatter
import pylab
import matplotlib.pyplot as plt
import pandas as pd
from pandas import Series, DataFrame
import numpy as np

file_name = '/Users/joedanger/Desktop/Python/scatter_python.csv'

data = DataFrame(pd.read_csv(file_name))

y = np.log(data['o_value'], dtype='float64')
x = np.log(data['time_diff_day'], dtype='float64')

fig = plt.figure()
plt.scatter(x, y, c='blue', alpha=0.05, edgecolors='none')
fig.suptitle('test title', fontsize=20)
plt.xlabel('time_diff_day', fontsize=18)
plt.ylabel('o_value', fontsize=16)
plt.xticks([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4])

plt.grid(True)
pylab.show()

let matplotlib take the log for you: matplotlib为你记录日志:

fig = plt.figure()
ax = plt.gca()
ax.scatter(data['o_value'] ,data['time_diff_day'] , c='blue', alpha=0.05, edgecolors='none')
ax.set_yscale('log')
ax.set_xscale('log')

If you are using all the same size and color markers, it is faster to use plot 如果您使用所有相同的尺寸和颜色标记,则使用plot会更快

fig = plt.figure()
ax = plt.gca()
ax.plot(data['o_value'] ,data['time_diff_day'], 'o', c='blue', alpha=0.05, markeredgecolor='none')
ax.set_yscale('log')
ax.set_xscale('log')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM