1

Question:

How to set up scaled axes with hvplot? [https://hvplot.pyviz.org/]

Code example:

I have the following code giving me the figure hereafter but the lat and long axes are not equal. How to have a 1:1 ratio between the two axes?

import os, sys
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import hvplot.pandas
pos = pd.read_csv(os.path.join('my_gps_positions.csv'))
pos.hvplot.scatter(*'lat lng'.split())

Here's the GPS file content:

dataframe screenshot

And the resulting graph with unequal axes in my notebook:

hvplot with bokeh

swiss_knight
  • 5,787
  • 8
  • 50
  • 92

2 Answers2

2

You could adjust the width and the height parameter of the plot:

df.hvplot.scatter(x='lat', y='lon', width=500, height=500)

Or do you mean the range of the axes? They can be set by parameter xlim and ylim, for example:

df.hvplot.scatter(x='lat', y='lon', xlim=(6, 8), ylim=(45, 47))

Since you're plotting latitudes and longitudes you should definitely take a look at geoviews: http://geoviews.org/

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96
  • Neither solution give me the same scale on the X and Y axes. What I want is that for example both 1 degree on the Y and X axis is printed out on the screen as being the same length in P pixel or C centimeters. Thanks for the geoviews lib, I didn't explored it but I will. – swiss_knight Oct 07 '19 at 12:01
  • Hi s.k, if you find a good solution to your problem, can you put the answer here? – Sander van den Oord Oct 07 '19 at 12:06
1

longitude and latitude units should not be the same distance, except right on the equator. So normally you would plot these with hvplot as:

df.hvplot.points(x='lon', y='lat', geo=True, tiles='OSM')

but if you really want to force them to be the same, you can use aspect:

df.hvplot.scatter(x='lon', y='lat', aspect='equal')
Rich Signell
  • 14,842
  • 4
  • 49
  • 77