# Plot of a function from x=0 to x=1 is not shown

**URL:** <https://discourse.julialang.org/t/plot-of-a-function-from-x-0-to-x-1-is-not-shown/128091>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [April 15, 2025, 11:31am UTC](https://discourse.julialang.org/t/plot-of-a-function-from-x-0-to-x-1-is-not-shown/128091 "2025-04-15T11:31:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [April 15, 2025, 11:31am UTC](https://discourse.julialang.org/t/plot-of-a-function-from-x-0-to-x-1-is-not-shown/128091/1 "2025-04-15T11:31:12Z")

</div>

Hi all,

I tried to plot a function `\frac{1}{(x-1)^{2/3}}` but it can only plot the function from x=1 to the right. There should also be the plot from from `x=0` to `x=1` toward infinity.

This is the suppose to be function plot:

 ![1](https://global.discourse-cdn.com/julialang/original/3X/6/4/643c66f9ccbd9f1e4ff770f21362de8ff86c9be6.png)

This is my code to plot with JULIA:

```julia
using Plots, LaTeXStrings, Plots.PlotMeasures # ignore any warnings 
gr()

f(x) = 1/(x-1)^(2/3)

plot(f,-1,6; color=:blue, xlims=(-1,6), xtick=-1:1:6, yaxis=false,ylims=(-1,10), 
	framestyle=:zerolines, label=L"y = f(x) = \frac{1}{(x-1)^{2/3}}",
	top_margin=10mm, legend=:topright)

```

 ![Screenshot from 2025-04-13 10-43-27](https://global.discourse-cdn.com/julialang/original/3X/f/2/f2444cec87318d67ef32499ca265b01e6037516f.png)

I also try to use matplotlib by calling from C++ and it is the same,

```julia
// g++ main.cpp -o main -std=c++11 -I/usr/include/python3.9 -lpython3.9 -DWITHOUT_NUMPY
// g++ main.cpp -o main -std=c++11 -lpython3.9 -I/usr/include/python3.9 -I/usr/lib/python3.9/site-packages/numpy/core/include

#include "matplotlibcpp.h"
#include <cmath>

double division(double x, double y)
{
	return x/y;
}
namespace plt = matplotlibcpp;
int main()
{
	// Prepare data.
	int n = 1000;
	std::vector<double> x(n), y(n), z(n);
	for(int i=0; i<n; ++i) 
	{
		x.at(i) = i;
		y.at(i) = pow(i-1,-division(2,3));
	}

	// Set the size of output image to 1200x780 pixels
	plt::figure_size(1200, 780);
	// Plot line from given x and y data. Color is selected automatically.
	plt::plot(x, y);
	// Plot a line whose name will show up as "x exp(-x)" in the legend.
	plt::named_plot("1/(x-1)^(2/3)", x, y);
	// Set x-axis to interval [0,10]
	plt::xlim(0, 10);
	// Add graph title
	plt::title("1/(x-1)^(2/3)");
	// Enable legend.
	plt::legend();
	plt::show();
	// Save the image (file format is determined by the extension)
	// plt::save("./basic.png");
}

```

 ![Screenshot from 2025-04-13 10-36-17](https://global.discourse-cdn.com/julialang/original/3X/5/e/5ef17867ee065a1ddab23ec0cf5021c8eb15caad.png)

and also with gnuplot:

```julia
// Compile it with:
// g++ -o main main.cpp -lboost_iostreams 

#include <vector>
#include <cmath>
#include <utility>
#include <boost/tuple/tuple.hpp>

#include "gnuplot-iostream.h"

int main() {
	Gnuplot gp;

	// Don't forget to put "\n" at the end of each line!
	gp << "set xrange [-2:4]\nset yrange [0:5]\n";
	// '-' means read from stdin. The send1d() function sends data to gnuplot's stdin.
	gp << "f(x) = 1/(x-1)**(0.666667)\n";
	
	gp << "plot f(x) title 'f(x) = 1/(x-1)^{2/3}'\n";

	
	return 0;
}

```

 ![Screenshot from 2025-04-13 10-37-13](https://global.discourse-cdn.com/julialang/original/3X/6/2/6294a0c98e86c55ee663018b76eac7c1d5ab3624.png)

It seems even matplotlib and gnuplot cannot plot the function from `x=0` to `x=1`

---

<div class="post-metadata">

**Author:** ![\_bernhard](https://avatars.discourse-cdn.com/v4/letter/_/bc79bd/32.png) [@\_bernhard](https://discourse.julialang.org/u/_bernhard)\
**Post date:** [April 15, 2025, 11:32am UTC](https://discourse.julialang.org/t/plot-of-a-function-from-x-0-to-x-1-is-not-shown/128091/2 "2025-04-15T11:32:55Z")

</div>

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [April 15, 2025, 11:34am UTC](https://discourse.julialang.org/t/plot-of-a-function-from-x-0-to-x-1-is-not-shown/128091/3 "2025-04-15T11:34:24Z")

</div>

I accidentally hit `tabs` and it is posted before I finish writing. Sorry.

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [April 15, 2025, 12:24pm UTC](https://discourse.julialang.org/t/plot-of-a-function-from-x-0-to-x-1-is-not-shown/128091/4 "2025-04-15T12:24:45Z")

</div>

The problem is that exponentiation with a float exponent is only defined for a ~~strictly positive~~ non-negative base:

```julia-repl
julia> f(0.5) # involving (-0.5)^(2/3)
ERROR: DomainError with -0.5:
Exponentiation yielding a complex result requires a complex argument.
Replace x^y with (x+0im)^y, Complex(x)^y, or similar.
...

```

If you just rewrite `f` as

```julia
f(x) = (1/(x-1)^2)^(1/3)

```

then you won’t run into any issues.

 ![plot](https://global.discourse-cdn.com/julialang/original/3X/9/7/970a916e99a02b0af0e1278af7ba54f3828a1c80.png)

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [April 15, 2025, 12:42pm UTC](https://discourse.julialang.org/t/plot-of-a-function-from-x-0-to-x-1-is-not-shown/128091/5 "2025-04-15T12:42:59Z")

</div>

Wow thanks a lot, I just learn it now solving this needs only to rewrite `f`.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 15, 2025, 1:06pm UTC](https://discourse.julialang.org/t/plot-of-a-function-from-x-0-to-x-1-is-not-shown/128091/6 "2025-04-15T13:06:45Z")

</div>

> [@eldee](#):
>
> If you just rewrite `f` as `f(x) = (1/(x-1)^2)^(1/3)`

Or alternatively use the `cbrt` function, which allows negative arguments and is also probaby more efficient than generic exponentiation `y^(1/3)`, e.g. `f(x) = 1/cbrt(x)^2`

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 15, 2025, 1:09pm UTC](https://discourse.julialang.org/t/plot-of-a-function-from-x-0-to-x-1-is-not-shown/128091/7 "2025-04-15T13:09:53Z")

</div>

For the record, Plots.jl seems to do the right thing. For values x\<1, the original function is not properly defined, the fractional power has complex solutions, and the function is multivalued.
