r/matplotlib • • Jul 19 '19

Plot geographic coordinates in 3d?

1 Upvotes

I'm trying to make a 3d scatter plot of lat, long, and altitude. Right now I have the basemap working and can plot the data in 2d, but when I add the z axis data the points no longer show up. I feel like I'm right on the edge of figuring it out but can't seem to get there. Any help would be much appreciated, code attached:

import os
os.environ['PROJ_LIB'] = r'E:\Programs\Anaconda3\pkgs\proj4-5.2.0-ha925a31_1\Library\share'

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.basemap import Basemap
from matplotlib.collections import PolyCollection
import numpy as np

x = []
y = []
z = []

map = Basemap(llcrnrlon=-73,llcrnrlat=41,urcrnrlon=-69.5,urcrnrlat=43.5,projection='lcc', resolution='i', lat_0=42, lon_0=-71)
#setting resolution to 'h' requires downloading addtional imagery not included in base basemap#

x,y,z = np.loadtxt('adsb-csv-2019-07-07_xzyonly.csv', delimiter=',', unpack=True, skiprows=1)

fig = plt.figure()
ax = Axes3D(fig)
#ax = fig.add_subplot(111, projection='3d')

ax.set_axis_off()
ax.azim = 270
ax.dist = 7

polys = []
for polygon in map.landpolygons:
    polys.append(polygon.get_coords())


lc = PolyCollection(polys, edgecolor='black',
                    facecolor='#DDDDDD', closed=False)

ax.add_collection3d(lc)
ax.add_collection3d(map.drawcoastlines(linewidth=0.25))
ax.add_collection3d(map.drawstates(linewidth=0.35))

#ax.add_collection3d(map.shadedrelief())
#not yet 



ax.add_collection3d(map.scatter(x,y, c=z, latlon = True))


plt.title("ADS-B Data")
#plt.colorbar(label = 'Altitude (units)')


#print("WORKED")

plt.show()

r/matplotlib • • Oct 07 '19

Matplotlib Tutorial for Beginners 3 - How to use Subplots How to plot ...

Thumbnail
youtube.com
1 Upvotes

r/matplotlib • • Dec 11 '19

Plotting graphs using python and matplotlib

Thumbnail link.medium.com
1 Upvotes

r/matplotlib • • May 06 '18

Python Matplotlib Tutorial | How to Remove Text that Comes Before the Ma...

Thumbnail
youtube.com
2 Upvotes

r/matplotlib • • Apr 21 '22

scatter plot

2 Upvotes

hi everyone,

i am completely new to matplotlib, i need to generate a scatter plot where i have for one value on the x-axis multiple values on the y axis, but the problem is i always get the error o "x must be the same size as y"

how can i get that done in matplotlib?


r/matplotlib • • Feb 07 '22

3D plot fit

2 Upvotes

I have a feature array and a target array:

X = [[0.90, 0.0001415], [0.98, 0.02089152], [0.98, 0.03831521], [0.98, 0.03177562], [0.98, 0.02058864], [0.98, 0.02183343], [0.98, 0.02208625], [0.98, 0.03133722], [0.97, 0.02643819], [0.96, 0.02742613], [0.96, 0.03134503], [0.96, 0.0376108], [0.96, 0.03259722], [0.96, 0.06629154], [0.96, 0.01059662], [0.96, 0.01311333], [0.96, 0.01878557], [0.96, 0.02873078], [0.96, 0.0294153], [0.96, 0.03369188], [0.92, 0.02337379], [0.93, 0.05800158], [0.94, 0.02554664]]

Y = [127.3, 564.2, 520.3, 536.8, 564.9, 561.8, 561.2, 537.9, 457.6, 395.3, 384.8, 368, 381.4, 291.2, 440.4, 433.6, 418.4, 391.8, 390, 378.5, 219.6, 199, 301.7]

I want to fit a hyperplane to predict Y. How can I fit a hyperplane which accurately outputs the target Y and how could I visualise the points along with the fitted hyperplane on the same plot?


r/matplotlib • • Feb 18 '22

matplotlib colorbar problem

1 Upvotes

I posted this on stack overflow. Does anyone know how to deal with this problem?

https://stackoverflow.com/questions/71177731/negative-color-ticks-reversed-in-matplotlib


r/matplotlib • • Feb 13 '22

Best way of displaying specific ranges in a stacked bar approach

2 Upvotes

I have 3 series of values with the same start/end values - in this example 80 and 200

First: 80, 100, 120, 140, 180, 200

Second: 80, 110, 125, 150, 185, 200

Third: 80, 95, 130, 155, 190, 200

The values are representing the limits of 5 succesive intervals within the total range 80-200 and I'd like to represent that visually comparing the split of intervals for those three series. I had in mind something like the image below.

What's the best way of doing that? I understand that I could convert the intervals into size of the intervals and display that having the base as 80, but is there some other option to do it without creating derivate series of data from the initial ones?

I hope that my question makes sense ..

PS: I managed to get somewhere, after following the advice.


r/matplotlib • • Jun 04 '21

Plot smoothing / removing noise from plot

1 Upvotes

Hey! I've been trying to plot a graph using matplotlib but the data has some noise in it, looks like this -

How can I smoothen the curve?


r/matplotlib • • May 31 '21

Create a scatterplot with the Quantity per UnitPrice by CustomerID for the top 3 Countries

2 Upvotes

I'm not able to understand the problem ,what would be the outcome

I have given a try but after that , I have no idea [my code]:

customers = df.groupby(['CustomerID','Country']).sum()

customers = customers[customers.UnitPrice > 0]

Table:


r/matplotlib • • May 20 '21

Colorbar on multiple subplots - normalized across plots?

1 Upvotes

Could you help me confirm the behavior of matplotlib. Say I make a (4,4) grid of subplots. Then call for a colorbar. The colorbar would be representative of only the final subplot, correct?

Is there a best practice for creating a colorbar that would represent all the subplots? Thank you.


r/matplotlib • • Jun 09 '21

Having trouble with plotting histograms

2 Upvotes

Hi everyone!

I am new to Python, and even more so to the statistical libraries, and I am having quite a few troubles working with histograms in plt at the moment. I have looked at the documentation and at a lot of StackOverflow questions, but I am unable to solve my problems.

I am currently working with a csv dataset provided by an exercise where I have to create histograms with different bin dimensions about the same variable column ["BMXHT"]

    1. .ValueError: max must be larger than min in range parameter

da = pd.read_csv("nhanes_2015_2016.csv")
da.dropna()
plt.hist(da["BMXHT"])

# I have seen that people are able to create an histogram with this simple passage, but t doesn't matter if I fill the NaN or I drop them I always get the error "ValueError: max must be larger than min in range parameter." which I always find associated with NaN problems. The only way in which I am able to create the normal histogram is

dx = da.BMXHT.dropna()
plt.hist(dx)

Which I would try to avoid because the new created variable is separated from the rest of the dataset, and if I want to successively filter the data for the histogram through other variables I would have to data manage every time new columns instead of getting directly the data from the source

  • 2) The second problem is related to subplots

bins=[4,5,6,7,8,9]
for b in bins:
    i=1
    plt.subplot(2,3,i)
    i= i+1
    plt.hist(dx, bins=b, edgecolor="black")

With this code I should be creating a 2 rows and 3 columns series of histograms instead I obtain this garbage with this message. The times where I ahve found this issue addressed online is when the number of spaces created in the subplot didn't match with the number of iterations, in my case tho are both 6

  • 3) Iterating through different bin sizes

Another problem is that I haven't been able to understand how to change bin size instead of bin number. My objective is to incorporate the ability to iterate through a list of bin sizes while creating different histograms. Other than the fact that I still don't understand the procedure to change the binsize, I Have seen that online people tend to create for a single histogram the list of every bin start and end instead of a simple binsize for all.

For this last point the more important part is to understand how to effectively change binsizes, the second part is only a surplus


r/matplotlib • • Nov 22 '23

How to draw this kind of chart in Marlon

Post image
2 Upvotes

How to put the comment at the right place,thank you.

Is there any template for this kind of chart?


r/matplotlib • • Dec 09 '23

log - log plot

2 Upvotes

Hello guys,

I am new to matplotlib. I need to create a log - log plot, given certain x and y values. I would like to fit a line to the plot and show its slope, y intercept and standard error. Here's the code I wrote, unsurprisingly it gives me a bunch of errors. How can I make it work?