python:散点图对数刻度 [英] python: scatter plot logarithmic scale

查看:66
本文介绍了python:散点图对数刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我采用两个数据系列的对数并将其绘制.我想通过将 x 轴的每个刻度值提高到 e(自然对数的反对数)的幂来更改它.

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).

换句话说.我想绘制两个系列的对数,但水平具有x轴.

In other words. I want to graph the logarithms of both series but have x-axis in levels.

这是我正在使用的代码.

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()

推荐答案

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')

如果您使用所有相同的大小和颜色标记,使用 plot

If you are using all the same size and color markers, it is faster to use 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')

这篇关于python:散点图对数刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆