Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Distortion in Axes

Hi,
I’ve been trying to plot a circle in plotly through a simple graph in python, but the result is an ellipsis instead of a circle. Although the values in the x-axis and y-axis are both correct, the image that appears to me is not a circle, as you can see.
Here’s the code:

import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go

# Polar Coordinates
r = 1
theta = np.linspace(0, 2*np.pi, 200)

x_circle = 1 + r*np.cos(theta)
y_circle = 1 + r*np.sin(theta)

# It plots the points of the list outside the circle
trace = go.Scatter(
    x=x_circle,
    y=y_circle,
    name='Circle',
    mode='lines',
    line=dict(
        width=1.0,
        color='rgba(66, 28, 82, 0.9)'
    )
)

data = [trace]

# It sends authentication
py.sign_in('*******', '**********')  # Intentionally hidden

# It plots scatter
py.plot(data, filename='basic-scatter')

How can I fix this distortion, so that it appears a circle instead of an ellipsis?

@dieuler Your plot is an ellipse because you didn’t set the width and height of the plot rectangle. In this case the width is 700, and height 450, by default. To get a circle define the dict layout as follows:

layout=dict(autosize=False,
            width=600,
            height=600)
fig=dict(data=[trace], layout=layout)
py.iplot(fig, filename='mycircle')
1 Like

Thank you, @empet! I followed your suggestion and it worked but not completely, here’s the result:

It’s almost a circle, but it doesn’t seem to be a circle yet (the x-axis seems to be slightly larger than y-axis for me). Here’s the code I used:

import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go

# Escrevo as coordenadar polares
r = 1
theta = np.linspace(0, 2*np.pi, 200)

x_circle = 1 + r*np.cos(theta)
y_circle = 1 + r*np.sin(theta)

# It plots the points of the list outside the circle
trace = go.Scatter(
    x=x_circle,
    y=y_circle,
    name='Circle',
    mode='lines',
    line=dict(
        width=1.0,
        color='rgba(66, 28, 82, 0.9)'
    )
)

layout = dict(
    autosize=False,
    width=600,
    height=600
)

data = [trace]

fig = dict(data=data, layout=layout)

# It sends authentication
py.sign_in('*******', '*****************')  # Intentionally hidden

# It plots scatter
py.plot(fig, filename='basic-scatter')

You should tune the height until the plot looks like a circle. In my notebook, with height=650 it’s OK. This supplementary height is necessary because from the total height, 100px are reserved by the default top margin. Details on the default settings in layout can be found here: https://plot.ly/python/reference/#layout.

1 Like

Hmmm got it! Thank you!