axes

What is the correct way to replace matplotlib tick labels with computed values?

雨燕双飞 提交于 2019-11-29 00:08:29
I have a figure with a log axis and I would like to relabel the axis ticks with logs of the values, rather than the values themselves The way I've accomplished this is with plt.axes().set_xticklabels([math.log10(x) for x in plt.axes().get_xticks()]) but I wonder if there isn't a less convoluted way to do this. What is the correct idiom for systematically relabeling ticks on matplotlib plots with values computed from the original tick values? tacaswell Look into the Formatter classes. Unless you are putting text on your ticks you should almost never directly use set_xticklabels or set

Reversed order after coord_flip in R

旧巷老猫 提交于 2019-11-28 23:08:15
Data example from dbv: gender Sektion 1 m 5 2 m 5 3 w 3B 4 w 3B 5 w 3B 6 m 4 I have the following plot: Sekplot <- ggplot(dbv,aes(x=Sektion, fill=factor(gender), stat="bin", label = paste(round((..count..)/sum(..count..)*100), "%"))) Sekplot <- Sekplot + geom_bar(position="fill") Sekplot <- Sekplot + scale_y_continuous(labels = percent) Sekplot <- Sekplot + labs(title = "test") Sekplot <- Sekplot + scale_fill_discrete(name="test", breaks=c("m", "w", "k.A."), labels=c("m", "w", "k.A.")) Sekplot <- Sekplot + geom_hline(aes(yintercept = ges, linetype = "test"), colour = "black", size = 0.75, show

How to place the intercept of x and y axes at (0 , 0) and extend the x and y axes to the edge of the plot [duplicate]

為{幸葍}努か 提交于 2019-11-28 21:21:30
This question already has an answer here: Set R plots x axis to show at y=0 2 answers Suppose I want to plot x^2 . I can use curve() as follows. curve(x^2, -5, 5) However, I would like the axes to go through (0, 0). I could do something as follows: curve(x^2, -5, 5, axes=FALSE) axis(1, pos=0) axis(2, pos=0) abline(h=0) abline(v=0) And I end up getting something like below, which looks OK. But the only gripe I have is that this way of plotting axes makes the actual axes - for example the segment between -4 and 4 of the x-axis - thicker than the segments to the right side and the left side. The

Matplotlib/pyplot: How to enforce axis range?

允我心安 提交于 2019-11-28 20:02:45
I would like to draw a standard 2D line graph with pylot, but force the axes' values to be between 0 and 600 on the x, and 10k and 20k on the y. Let me go with an example... import pylab as p p.title(save_file) p.axis([0.0,600.0,1000000.0,2000000.0]) #define keys and items elsewhere.. p.plot(keys,items) p.savefig(save_file, dpi=100) However, the axes still adjust to the size of the data. I'm interpreting the effect of p.axis to be setting what the max and min could be, not enforcing them to be the max or min. The same happens when I try to use p.xlim() etc. Any thoughts? Thanks. Calling p.plot

数据分析-信用卡反欺诈模型

£可爱£侵袭症+ 提交于 2019-11-28 18:55:48
本文通过利用信用卡的历史交易数据进行机器学习,构建信用卡反欺诈预测模型,对客户信用卡盗刷进行预测 一、项目背景 对信用卡盗刷事情进行预测对于挽救客户、银行损失意义十分重大,此项目数据集来源于Kaggle,数据集包含由欧洲持卡人于2013年9月使用信用卡进行交的数据。此数据集显示两天内发生的交易,其中284,807笔交易中有492笔被盗刷。数据集非常不平衡,积极的类(被盗刷)占所有交易的0.172%。因判定信用卡持卡人信用卡是否会被盗刷为二分类问题,解决分类问题我们可以有逻辑回归、SVM、随机森林算法,也可利用boost集成学习的XGboost算法进行数据的训练与判别,本文中采用逻辑回归算法进行测试。​ 二、探索性数据分析 2.1 理解数据 import numpy as np import pandas as pd data = pd.read_csv('E:\\数据挖掘\\Project\\信用卡反欺诈模型\\creditcardfraud\\creditcard.csv') len(data) data.info() data.head() Data columns (total 31 columns): Time 284807 non-null float64 V1 284807 non-null float64 V2 284807 non-null float64 V3

GGplot custom scale transformation with custom ticks

☆樱花仙子☆ 提交于 2019-11-28 14:14:41
I'm attempting to use a custom scale/axis transformation, like so: library(ggplot2) library(scales) dat <- data.frame( time.tot = c(407.17, 168.83, 127.8, 108.88, 69.04, 68.5, 59.76, 407.17, 168.83, 127.8, 108.88, 69.04, 68.5, 59.76, 407.17, 168.83, 127.8, 108.88, 69.04, 68.5, 59.76), error = c(0, 0.01, 0.05, 0.1, 0.5, 0.7, 1, 1.91e-06, 0.00229, 0.00884, 0.0172, 0.128, 0.128, 0.22, 1.43e-08, 0.000337, 0.00121, 0.00221, 0.0123, 0.0123, 0.0213, 0, 0.01, 0.05, 0.1, 0.5, 0.7, 1, 1.91e-06, 0.00229, 0.00884, 0.0172, 0.128, 0.128, 0.22, 1.43e-08, 0.000337, 0.00121, 0.00221, 0.0123, 0.0123, 0.0213),

python check if figure is 2d or 3d

对着背影说爱祢 提交于 2019-11-28 11:12:00
问题 In matlab with a figure, to check if it is 3D figure or 2D figure I use: V=axis; and check the number of components of V (4 for 2d figure, 6 for 3d figure). How can i implement this with python and matplotlib? 回答1: You can use the name of the axes. plt.gca().name or ax.name if ax is the axes. A 3D axes' name will be "3d" . A 2D axes' name will be "rectilinear" , "polar" or some other name depending on the type of plot. You can therefore check if ax.name == "3d": # axes is 3D, do something

matplotlib3 --pyplot.plot解释

柔情痞子 提交于 2019-11-28 09:02:57
作为最常用的绘图函数之一,我们要比较详细的介绍了。 matplotlib.pyplot.plot(*args, scalex=True, scaley=True, data=None, **kwargs) API: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html 返回值:对应于每条线的 Line2D实例的 列表 plot y-x as lines and/or markers 调用实例: 绘制 单个y-x plot([x], y, [fmt], data=None, **kwargs) 在一个Aaxes 中绘制多个y-x plot([x], y, [fmt], [x2], y2, [fmt2], …, **kwargs) 其中, 可选参数 fmt 定义图的基本形式,比如颜色,标记(x,y)点的形状,和曲线的类型[color, marker and linestyle]。 先讲一下其他的几个参数: data 在绘制一些标签数据(比如,可以通过obj[‘y’]索引到的数据), 不用提供数据x,y。可以将对象名传给参数data,只需要传给x,y的标签就好。 其中,所有索引的对象都支持,比如 dict, pandas.DataFrame or structed numpy array 前两个参数不是参数x, y,

Matplotlib 入门(持续学习中)

醉酒当歌 提交于 2019-11-28 07:17:21
Matplotlib 入门 使用思路:建立画板-建立画布-绘制图像-添加辅助显示 import matplotlib . pyplot as plt # 创建画布 plt . figure ( ) # 绘制图像 plt . plot ( [ 1 , 0 , 9 ] , [ 4 , 5 , 6 ] ) # 显示图像 plt . show ( ) 实例:一周天气情况 plt . figure ( figsize = ( 15 , 5 ) , dpi = 80 ) plt . plot ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] , [ 18 , 17 , 11 , 11 , 19 , 20 , 18 ] ) plt . savefig ( "1.PNG" ) plt . show ( ) 实例2:1小时内每分钟温度变化 import random import matplotlib . pyplot as plt # 获取数据 x = range ( 60 ) y_shanghai = [ random . uniform ( 16 , 18 ) for i in x ] y_beijing = [ random . uniform ( 1 , 3 ) for i in x ] # 创建画布 plt . figure ( figsize = ( 15 , 5 ) ,

Strange error with matplotlib axes labels

余生颓废 提交于 2019-11-28 07:11:51
I'm very new to Python and programming in general, so apologies in advance if I'm missing something obvious. I'm trying to plot a graph and label the axes, but every time I try to label the y axis an exception is raised. I wrote the code below in a new script to make sure the problem wasn't coming from somewhere else in the module. I'm using Python 3.4. from numpy import * from matplotlib import * a = [1, 2, 3, 4, 5] b = [2, 3, 2, 3, 2] pyplot.plot(a, b) pylab.xlabel("Time") pylab.ylabel("Speed") Every time, I get the error 'TypeError: 'str' object is not callable' for the final line. If I