简体   繁体   English

当使用 matplotlib 从 CSV 文件绘制时,X、Y 轴上的 0 值未绘制,我需要绘制它们

[英]When plotting from a CSV file using matplotlib, 0 values on X, Y axis are not plotting and I need them to be plotted

The 0 values from my CSV file are not plotting, any idea as to why this is happening and how I can ensure they are plotted?我的 CSV 文件中的 0 值没有绘制,关于为什么会发生这种情况以及我如何确保绘制它们的任何想法?

import pandas as pd 
import numpy as np from matplotlib 
import pyplot as plt  

columns = np.array(["Ast", "Gls"]) 
df = pd.read_csv(r"document.csv", usecols=columns) 
print("Contents in csv file:\n", df)  

colors =(["red"])   
size = ([500])  

plt.scatter(df.Ast, df.Gls, c=colors, s=size, alpha=0.5, cmap='viridis') 
plt.show()
Contents in csv file:
     Gls  Ast
0     2    1
1     4    5
2     0    3
3     1    9
4     1    1
5     4    2
6     1    1
7     5    4
8     7    4
9     4    1
10    5    6
11    4    1
12    0    1
13    2    2
14    3    0
15    1    0
16    0    2
17    4    5
18    0    1
19    4    3
20    2    5
21   14   11
22    4    1
23    3    6
24    7    1
25    2    5
26    9    3

For example all the results with figures above zero are plotted.例如,绘制所有数字大于零的结果。

This is the plot I'm getting with your code and data:这是我从您的代码和数据中获取的 plot:

在此处输入图像描述

You can clearly see that all points are accounted for, even the ones in which X or Y is zero.您可以清楚地看到所有点都被考虑在内,即使是 X 或 Y 为零的点。

There are a few points having a darker red color: it means that there are 2 or more points sharing the same location.有几个点呈深红色:表示有 2 个或更多点共享同一位置。

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

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